(Mac)-bash:__git_ps1:找不到命令 [英] (Mac) -bash: __git_ps1: command not found
问题描述
-bash:__git_ps1:找不到命令
我已经试过了,只需将它输入到终端中即可: __ git_ps1
。我也在 .bash_profile
if if [ -f〜/ .git-completion.bash];然后
source〜/ .git-completion.bash
export PS1 ='[\W] $(__ git_ps1(%s)):'
fi
正如您可以看到/说出的那样,是的,我已经安装了自动完成功能,并且它确实很棒! / p>
我遇到过这个问题: PS1的env变量不适用于mac ,它给出了代码
别名__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];然后
source〜/ .git-completion.bash
export PS1 ='[\W] $(__ git_ps1(%s)):'
fi
现在改变错误输出:
<$ c $注意:
strong>我也在源代码下面移动了别名,没有任何区别。我有 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
A ls -la
然后列出 .git-completion.bash
file。
编辑10/13/12 - 由 Mark Longair解决(下)
以下代码在 .bash_profile
中适用于我,而另一些则不适用于...
if [-f〜/ .git-prompt.sh];然后
source〜/ .git-prompt.sh
export PS1 ='Geoff [\W] $(__ git_ps1(%s)):'
fi
你已经安装了 git-completion .bash from
master
- 在git的开发历史中,这是在将 __ git_ps1
函数从完成功能转换为新文件( git-prompt.sh
)。引入此更改的提交(解释原因)为 af31a456 。
我仍然会建议您只输入 git-completion.bash
(或 git-但是,如果由于某种原因,您仍希望通过使用此功能来使用此功能,请使用以下命令:
master
单独下载的脚本,您应该同样下载 git-prompt.sh
: curl -o〜/ .git-prompt.sh \
https://raw.githubusercontent.com/git/git/master/contrib /completion/git-prompt.sh
...并将以下行添加到〜/ .bash_profile
:
source〜/ .git-prompt.sh
然后您的 PS1
变量包含 __ git_ps1'%s'
应该可以正常工作。
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 it into the terminal as is: __git_ps1
. I've also tried it out in the .bash_profile
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
As you might be able to see/tell, yes, I do have the auto-completion installed and it does work great!
I came across this question: " PS1 env variable does not work on mac " which gives the code
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
So I add it to my .bash_profile
hoping that it will change something. Well, it did. It just changed the error output.
Here's the .bash_profile
with the addition:
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
And now here's the changed error output:
sed: (%s): No such file or directory
Note: I've also moved the alias below the source with no difference. I have git version 1.7.12.1
This should be a simple change. Can someone please help me?
Edit 10/13/12
No, I definitely do not want to define __git_ps1 myself but was just trying to see if it would be recognized by doing so. Yes, I have the .git-completion.bash
file installed. Here's how I got auto completion on my machine.
cd ~
curl -OL https://github.com/git/git/raw/master/contrib/completion/git-completion.bash
mv ~/git.completion.bash ~/.git-completion.bash
A ls -la
then lists the .git-completion.bash
file.
Edit 10/13/12 - Solved by Mark Longair (below)
The following code worked for me in the .bash_profile
while others did not...
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
export PS1='Geoff[\W]$(__git_ps1 "(%s)"): '
fi
You've installed the version of git-completion.bash
from master
- in git's development history this is after a commit that split out the __git_ps1
function from the completion functionality into a new file (git-prompt.sh
). The commit that introduced this change, which explains the rationale, is af31a456.
I would still suggest that you just source the version of git-completion.bash
(or git-prompt.sh
) that is bundled with your installation of git.
However, if for some reason you still want to use this functionality by using scripts separately downloaded from master
, you should download git-prompt.sh
similarly:
curl -o ~/.git-prompt.sh \
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
... and add the following line to your ~/.bash_profile
:
source ~/.git-prompt.sh
Then your PS1
variable that includes __git_ps1 '%s'
should work fine.
这篇关于(Mac)-bash:__git_ps1:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!