taquaki-satwo
7/29/2019 - 4:51 AM

zshのPromptに軽量なgit情報を出力する

# http://tagussan.rdy.jp/blog/archives/677
# https://qiita.com/nishina555/items/f4f1ddc6ed7b0b296825

function git_branch() {
  # gitで管理されていないディレクトリは何も返さない
  if [ ! -e ".git" ]; then
    echo -n ""
  else
    echo -n "%B%F{blue}git:%f%F{red}($(git name-rev --name-only HEAD 2> /dev/null))%f%B "
  fi
}
 
setopt prompt_subst

local p_mark="%B%(?,%F{green},%F{red})%(!,#,➜)%f%b"
local p_cdir="%B%F{cyan}%C%f%B"
local p_git='$(git_branch)'
PROMPT="$p_mark  $p_cdir $p_git"