Re: git のブランチ名を zsh の右プロンプトに表示+ status に応じて色もつけてみた
git のブランチ名を zsh の右プロンプトに表示+ status に応じて色もつけてみた - ヤルキデナイズドだった
がすごい便利だったので、ディレクトリは表示させないようにして、ちょっとだけ表示するメッセージ弄ってみた。それだけ。
追記:元記事先のGistみたら.gitディレクトリ内に居る時の処理が加えられてたので追加。
追記2:gitが.git/index.lockを作れない時に警告が出ていたのを修正。右プロンプトが表示されない場合があるのでやっぱり削除...
追記3:
もうめんどくさいので追記しない。
俺が使ってる最新版が見たければこちらへどうぞ。
あとid:uasiさんの新しいエントリもあったのでそちらも貼っとく。
2009-10-17 - ヤルキデナイズドだった
あとこんなのもあるみたい。
Git だろうと Mercurial だろうと、ブランチ名をzshのプロンプトにスマートに表示する方法 - mollifier delta blog
autoload -Uz VCS_INFO_get_data_git; VCS_INFO_get_data_git 2> /dev/null function rprompt-git-current-branch { local name st color gitdir action if [[ "$PWD" =~ '/\.git(/.*)?$' ]]; then return fi name=`git branch 2> /dev/null | grep '^\*' | cut -b 3-` if [[ -z $name ]]; then return fi gitdir=`git rev-parse --git-dir 2> /dev/null` action=`VCS_INFO_git_getaction "$gitdir"` && action="($action)" st=`git status 2> /dev/null` if [[ -n `echo "$st" | grep "^nothing to"` ]]; then color=%F{green} elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then color=%F{yellow} elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then color=%B%F{red} else color=%F{red} fi echo "[$color$name$action%f%b]" } # プロンプトが表示されるたびにプロンプト文字列を評価、置換する setopt prompt_subst RPROMPT='`rprompt-git-current-branch`'