To get a prompt which indicates Git-branch in Zsh

前端 未结 9 1880
滥情空心
滥情空心 2020-12-04 09:12

I run the following codes separately as my prompt unsuccessfully in .zshrc. This suggests me that apparently I do not have a program called __git_ps1. It is not in MacPorts.

9条回答
  •  渐次进展
    2020-12-04 09:57

    A lot of these solutions seemed slow for me when mashing the return key, so here's an option that is basic and speedy:

    parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }
    
    setopt PROMPT_SUBST
    PROMPT='%9c%{%F{green}%}$(parse_git_branch)%{%F{none}%} $ '
    

    You'll get a prompt that looks like this: ~/dev/project (feature-branch) $

提交回复
热议问题