zshã§vcs_infoãçç¥ããªãã表示
Git だろうと Mercurial だろうと、ブランチ名をzshのプロンプトにスマートに表示する方法 - mollifier delta blogãåå½¢ã«ãã¦, 表示ã工夫ãã¦ã¿ã.
- 主ã«gitã使ã£ã¦ããã®ã§gitã®å ´åã¯VCSåã¯è¡¨ç¤ºããªã
- svnã®å ´åã¯ãªãã¸ã§ã³ã表示ããããã¨ã§èå¥ã§ããã®ã§VCSåã¯è¡¨ç¤ºããªã
- ãªãã¸ããªã®ãã¹ã¯ããã¶åºãªãã¦ããã
if [[ $ZSH_VERSION == (<5->|4.<4->|4.3.<10->)* ]]; then autoload -Uz vcs_info zstyle ':vcs_info:(git|svn):*' formats '%R' '%S' '%b' zstyle ':vcs_info:(git|svn):*' actionformats '%R' '%S' '%b|%a' zstyle ':vcs_info:*' formats '%R' '%S' '%s:%b' zstyle ':vcs_info:*' actionformats '%R' '%S' '%s:%b|%a' precmd_vcs_info () { psvar=() LANG=en_US.UTF-8 vcs_info repos=`print -nD "$vcs_info_msg_0_"` [[ -n "$repos" ]] && psvar[2]="$repos" [[ -n "$vcs_info_msg_1_" ]] && psvar[3]="$vcs_info_msg_1_" [[ -n "$vcs_info_msg_2_" ]] && psvar[1]="$vcs_info_msg_2_" } typeset -ga precmd_functions precmd_functions+=precmd_vcs_info PROMPT="%(!.%F{red}.%F{green})%U%n@%6>>%m%>>%u%f:%1(j.%j.)%(!.#.>) " local dirs='[%F{yellow}%3(v|%32<..<%3v%<<|%60<..<%~%<<)%f]' local vcs='%3(v|[%25<\<<%F{yellow}%2v%f@%F{blue}%1v%f%<<]|)' RPROMPT="$dirs$vcs" fi
if [[ $ZSH_VERSION == ... ã®è¡
vcs_infoã¯æ°ããã®zshã§ãªãã¨åãã, ãã¾ã«å¤ãç°å¢ã§åã.zshrcã使ããã¨ãããã®ã§, zshã®ãã¼ã¸ã§ã³ããã§ãã¯ãã¦ãã.
ztyle ':vcs_info:*' ... ã®è¡
- %R
- ãªãã¸ããªã«ã¼ãã®ãã«ãã¹
- %S
- ãªãã¸ããªã«ã¼ãããã®ç¸å¯¾ãã¹
- %b
- ãã©ã³ãæ å ±
- %a
- ã¢ã¯ã·ã§ã³
- %s
- VCSå
gitãsvnã®ã¨ãã¯%sãªãã§, ãã以å¤ã¯%s:ãã¤ãã.
repos= ...ã®è¡
print -nDãã¦ãããªãã¨ãã¼ã ãã£ã¬ã¯ããªã~ã«ãªããªã. reposãlocalãããªãã®ã¯, ãããçç¥ããããªãã¸ããªã®ãã¹ãç¥ããããªã£ããecho $reposã§åããããã«ãããã.
typeset ..., precmd_functions+= ã®è¡
PROMPT= ... ã®è¡
vcs_infoé¢ä¿ãªããã©, rootã«ãªã£ã¦ãã¨ã赤ãããã, ããã¯ã°ã©ã¦ã³ãã§å®è¡ä¸ã®ã¸ã§ãæ°ã表示ããã. ãã¨ãã¹ãåãé·ãã£ããå é ã®é¨åã ã表示ãã.
local dirs= ...ã®è¡
å³ããã³ããã®ãã£ã¬ã¯ããªè¡¨ç¤º. ãªãã¸ããªå ã§ã¯ãªãã¸ããªã«ã¼ãããã®ç¸å¯¾ãã¹ã, ããã§ãªããã°æ®éã«ã«ã¬ã³ããã£ã¬ã¯ããªã®ãã¹ã表示ãã.
[ # ãã®ã¾ã¾å°å %F{yellow} # ããããé»è² %3(v # if psvar[3] | # then %32<..< # 32æåãè¶ ãããå·¦å´ãã..ãã§çç¥ %3v # psvar[3](ãªãã¸ããªã«ã¼ãããã®ç¸å¯¾ãã¹ãå ¥ã£ã¦ãã)ã表示 %<< # å·¦å´çç¥ããã¾ã§ | # else %60<..< # 60æåãè¶ ãããå·¦å´ãã..ãã§çç¥ %~ # ã«ã¬ã³ããã£ã¬ã¯ããªã表示 %<< # çç¥ããã¾ã§ ) # fi %f # é»è²ããã¾ã§ ] # ãã®ã¾ã¾å°å
local vcs= ...ã®è¡
å³ããã³ããã®VCSæ å ±. [ãªãã¸ããªã«ã¼ã@ãã©ã³ã]ã®å½¢å¼.
%3(v # if psvar[3] | # then [ # ãã®ã¾ã¾å°å %25<\<< # 25æåãè¶ ãããå·¦å´ãã<ãã§çç¥ %F{yellow} # ããããé»è² %2v # psvar[2](ãªãã¸ããªã«ã¼ãã®ãã¹ãå ¥ã£ã¦ãã)ã表示 %f # é»è²ããã¾ã§ @ # ãã®ã¾ã¾å°å %F{blue} # ããããéè² %1v # psvar[1](ãã©ã³ãæ å ±ãå ¥ã£ã¦ãã)ã表示 %f # éè²ããã¾ã§ %<< # å·¦å´çç¥ããã¾ã§ ] # ãã®ã¾ã¾å°å | # else # ãªã«ãå°åããªã ) # fi