LoginSignup
25
26

More than 5 years have passed since last update.

zshのプロンプトにgitのブランチ名を色付きで表示する

Last updated at Posted at 2014-02-06

vcs_infoを使ってプロンプトにgitのブランチ名を表示させる時に、ブランチ名の部分に色づけをしてみました。

# vcs_infoロード    
autoload -Uz vcs_info    
# PROMPT変数内で変数参照する    
setopt prompt_subst    

# vcsの表示    
zstyle ':vcs_info:*' formats '%s][* %F{green}%b%f'    
zstyle ':vcs_info:*' actionformats '%s][* %F{green}%b%f(%F{red}%a%f)'    
# プロンプト表示直前にvcs_info呼び出し    
precmd() { vcs_info }    
# プロンプト表示    
PROMPT='[${vcs_info_msg_0_}]:%~/%f '    

結果は以下

プロンプト_1_324_44.png

また、コンフリクトが起きた時などaction nameが出るときは、その部分が赤く表示されます。

プロンプト_2_324_44.png

25
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
26