PS1 env variable does not work on mac

我怕爱的太早我们不能终老 提交于 2019-12-02 23:59:14

Mac OS X installations of Git don't have __git_ps1 included.

Use:

alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"

as a substitution.

such

The script you provided fails to detect git repos if the command __git_ps1 fails. Add this to ~/.bash_profile:

source /usr/local/git/contrib/completion/git-completion.bash
source /usr/local/git/contrib/completion/git-prompt.sh

Assuming you stored the script file as ~/.ps1, also add:

source ~/.ps1

  • This solution also enables tab completion for git.
  • Mac OS X installations of git do have __git_ps1 included, thanks sschuberth and cheapener for mentioning git-completion.bash.

On a new Yosemite mac using built in git, I used this:

source /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
export PS1='\[\e]0;\u@\h: \w\a\]\[\e[32;1m\]\u@\h:\w \[\e[33;1m\]$(__git_ps1 "[%s] ")\[\e[32;1m\]\$ \[\e[0m\]'

Note: on El Capitan, I had to change the path of the git scripts to /Applications/Xcode.app/Contents/Developer/usr/share/git-core and I guess you have to have XCode installed for this to work.

If you installed git through macports (git-core), you should add the following to ~/.bash_profile:

source /opt/local/etc/profile.d/bash_completion.sh
source /opt/local/share/git-core/git-prompt.sh  

The location of the git-prompt.sh seemed to have changed a few times.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!