(Mac) -bash: __git_ps1: command not found

后端 未结 19 1940
感动是毒
感动是毒 2020-11-30 16:20

I\'m trying to change my command promt in terminal. I keep getting the error:

-bash: __git_ps1: command not found

I\'ve tried it just by typing

19条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 16:49

    Following worked for me like a charm:

    Run following in your Terminal:

    curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
    

    Open/Create bash_profile:

    $ vi ~/.bash_profile
    

    Add following to the file:

    source ~/.bash_git
    export PS1='\[\033[01;32m\]os \[\033[01;34m\]\w $(__git_ps1 "[%s]")\$\[\033[00m\] '
    export GIT_PS1_SHOWDIRTYSTATE=1
    export GIT_PS1_SHOWUPSTREAM="auto"
    

    Finally, source it using:

    $ source ~/.bash_profile
    

    This will solve the problem of bash: __git_ps1: command not found.

    Also your prompt will change to "os ". To change "os" to something else, modify "os" string in export PS1 line.

提交回复
热议问题