Geo*_*off 215 git macos terminal ps1
我正在尝试在终端中更改我的命令promt.我一直收到错误:
-bash: __git_ps1: command not found
我只是通过在终端中键入它来尝试它:__git_ps1.我也试过了.bash_profile
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
Run Code Online (Sandbox Code Playgroud)
正如您可能看到/告诉的那样,是的,我确实已经安装了自动完成功能,它确实很有效!
我遇到了这个问题:" PS1 env变量在mac上不起作用 ",它给出了代码
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
所以我把它添加到我的.bash_profile希望它会改变一些东西.嗯,确实如此.它只是改变了错误输出.
这是.bash_profile添加的:
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
Run Code Online (Sandbox Code Playgroud)
现在这里是改变的错误输出:
sed: (%s): No such file or directory
注意:我也将源下的别名移动到没有区别.我有 git版本1.7.12.1
这应该是一个简单的改变.有人可以帮帮我吗?
编辑10/13/12
不,我绝对不想自己定义__git_ps1,而只是试图看看它是否会被识别出来.是的,我已.git-completion.bash安装该文件.这是我在我的机器上自动完成的方式.
cd ~
curl -OL https://github.com/git/git/raw/master/contrib/completion/git-completion.bash
mv ~/git.completion.bash ~/.git-completion.bash
Run Code Online (Sandbox Code Playgroud)
ls -la然后A 列出.git-completion.bash文件.
编辑10/13/12 - Mark Longair解决(下)
以下代码适用于我,.bash_profile而其他代码则没有......
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
export PS1='Geoff[\W]$(__git_ps1 "(%s)"): '
fi
Run Code Online (Sandbox Code Playgroud)
Mar*_*air 310
你已经安装了git-completion.bashfrom master-in git的开发历史版本,这是在将__git_ps1函数从完成功能拆分为新文件(git-prompt.sh)之后的提交之后.引入此更改的提交(解释其基本原理)是af31a456.
我仍然建议您只使用与您的git安装捆绑在一起的git-completion.bash(或git-prompt.sh)版本.
但是,如果由于某种原因您仍希望通过使用单独下载的脚本来使用此功能master,则应该git-prompt.sh类似地下载:
curl -o ~/.git-prompt.sh \
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
Run Code Online (Sandbox Code Playgroud)
...并将以下行添加到您的~/.bash_profile:
source ~/.git-prompt.sh
Run Code Online (Sandbox Code Playgroud)
然后你的PS1变量包括__git_ps1 '%s'应该工作正常.
hay*_*ark 59
在升级到OSX 10.9 Mavericks之后,我不得不引用以下文件来获取git shell命令完成和git提示再次工作.
来自我的.bash_profile或类似的:
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
#shell prompt example
PS1='\u $(__git_ps1 "(%s)")\$ '
Run Code Online (Sandbox Code Playgroud)
Ste*_*haw 41
你应该
$ brew install bash bash-completion git
然后在你的.bashrc中输入"$(brew --prefix)/ etc/bash_completion".
cho*_*hoc 14
以下为我工作就像一个魅力:
在终端中运行以下内容:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
Run Code Online (Sandbox Code Playgroud)
打开/创建bash_profile:
$ vi ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到文件中:
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"
Run Code Online (Sandbox Code Playgroud)
最后,使用以下方法来源:
$ source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
这将解决问题bash: __git_ps1: command not found.
您的提示也将更改为"os".要将"os"更改为其他内容,请在导出PS1行中修改"os"字符串.
从浏览器https://git-scm.com/download/下载git包
注意:如果您安装了curl [option] https://...下载选项,则必须确保您的系统支持SSL.所以对于新来者来说,从浏览器下载并直接从git安装程序安装就容易多了.
which git git --version当前版本应该是2.10.1.nano ~/.bash_profile或nano ~/.bashrc取决于您的修改地点.source /usr/local/git/contrib/completion/git-completion.bashsource /usr/local/git/contrib/completion/git-prompt.sh注意:在OSX升级到El Capitain之后,git安装位置从opt /目录更改为usr/local /,这就是为什么上面的一些旧答案在MacOS Sierra中不再起作用的原因.
将以下代码添加到PS1配置中:
选项1:直接添加到PS1: export PS1='\w$(__git_ps1 "(%s)") > '
.git-completion.bash它在我的主目录中,并且我可以在它的前面添加其他提示格式.这是我个人的提示,供您参考:export PS1='\t H#\! \u:\w$(__git_ps1 "{%s}") -->> '选项2:添加选择脚本
if [ -f ~/.git-completion.bash ]; then
export PS1='\w$(__git_ps1 "(%s)") > '
fi保存并使用配置文件:source ~/.bash_profile或source ~/.bashrc
带有颜色的 High Sierra 清洁解决方案!
没有下载。没有酿造。没有 Xcode
只需将它添加到您的 ~/.bashrc 或 ~/.bash_profile
export CLICOLOR=1
[ -f /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh ] && . /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUPSTREAM="auto"
PROMPT_COMMAND='__git_ps1 "\h:\W \u" "\\\$ "'
Run Code Online (Sandbox Code Playgroud)
升级到Yosemite时我遇到了同样的问题.
我不得不改变~/.bashrc,以source /usr/local/etc/bash_completion.d/git-prompt.sh代替旧的路径.
然后重新. ~/.bashrc获得你的效果.