/etc/zshrc

用最简洁的方式,在prompt里实现git branch的信息

增加parse_git_branch函数

final version

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

PS1="%F{12}%D%d~%#>%f%F{red}\$(parse_git_branch)%f"

ZSH prompt的简单生成器

https://zsh-prompt-generator.site/

ZSH现实git branch的另外一种方法

autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
#RPROMPT=$vcs_info_msg_0_
PS1="%F{cyan}%D%d~%#>%f"$vcs_info_msg_0_

reference

add git branch name to bash prompt

https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/

Leave a Reply

Your email address will not be published. Required fields are marked *