To get a prompt which indicates Git-branch in Zsh

前端 未结 9 1882
滥情空心
滥情空心 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:35

    Thank you for the links!

    I made the following prompt based on them

         # get the name of the branch we are on
         git_prompt_info() { 
             git branch | awk '/^\*/ { print $2 }'
         }
         get_git_dirty() { 
           git diff --quiet || echo '*'
         }
    
         autoload -U colors
         colors     
         setopt prompt_subst
    
         PROMPT='%{$fg[blue]%}%c %{$fg_bold[red]%}$(git_prompt_info)$(get_git_dirty)%{$fg[blue]%} $ %{$reset_color%}'                                           
    
         RPROMPT='%{$fg[green]%}%1(j.%j.)'        
    

    Please, suggest any improvements.

提交回复
热议问题