=======================================
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
function git_since_last_commit {
now=`date +%s`;
last_commit=$(git log --pretty=format:%at -1 2> /dev/null) || return;
seconds_since_last_commit=$((now-last_commit));
minutes_since_last_commit=$((seconds_since_last_commit/60));
hours_since_last_commit=$((minutes_since_last_commit/60));
minutes_since_last_commit=$((minutes_since_last_commit%60));
echo "${hours_since_last_commit}h${minutes_since_last_commit}m ";
}
PS1="[\[\033[1;32m\]\w\[\033[0m\]] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\$(git_since_last_commit)\[\033[0m\]$ "
=======================================
把上面的程式貼到 ~/.bash_profile,如果沒有就新建。
如果shell重啟之後沒反應,可以直接在~/.bashrc加入,讓它自動幫你執行 :
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
. ~/.bash_profile
fi
好了之後,重啟shell就會變成這樣 :DDD
顯示在哪個branch之下,還有溫馨小提示有多久沒有commit了 XD
常用的git alias :
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
No comments:
Post a Comment