Skip to content

Instantly share code, notes, and snippets.

@kejyun
Created November 30, 2012 07:53
Show Gist options
  • Save kejyun/4174397 to your computer and use it in GitHub Desktop.
Save kejyun/4174397 to your computer and use it in GitHub Desktop.
git prompt命令列特殊顏色及分支顯示設定
# 取得git branch名稱
function git_branch {
# 取得git branch,若此資料夾沒有git brangh,則將錯誤訊息丟至回收桶,回傳空值
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
# 若有取得git branch,則將取得的名稱「ref/heads/branchname」,並將前面的前贅詞去除,只保留branch名稱
echo "("${ref#refs/heads/}") ";
}
# 設定prompt名稱為 [資料夾路徑 現在時間] (branch)
# \e[1;32m:綠色
# \e[1;35m:紫色
# \e[1;36m:青色
PS1="[\[\e[1;32m\]\w\[\e[0m\] \[\e[1;35m\]\t\[\e[0m\]] \[\e[1;36m\]\$(git_branch)\[\e[0m\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment