-->

(苹果机)-bash:__git_ps1:命令未找到((Mac) -bash: __git_ps1:

2019-06-18 12:37发布

我想改变我的命令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

正如你可能可以看到/你能告诉的,是的,我已经安装了自动完成和它的工作太棒了!

“我碰到这个问题就来了PS1环境变量不能在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

而现在这里的改变错误输出:

sed: (%s): No such file or directory

注:我也感动源路径下的别名没什么区别。 我有Git版本1.7.12.1

这应该是一个简单的改变。 有人可以帮帮我吗?

编辑12年10月13日

不,我绝对不希望定义__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

一个ls -la然后列出了.git-completion.bash文件。

编辑12年10月13日- 马克Longair解决了(如下图)

下面的代码在为我工作.bash_profile ,而其他人没有?

if [ -f ~/.git-prompt.sh ]; then
  source ~/.git-prompt.sh
  export PS1='Geoff[\W]$(__git_ps1 "(%s)"): '
fi

Answer 1:

你已经安装的版本git-completion.bashmaster -在Git的发展历史,这是在提交后是打出__git_ps1从完成的功能函数到一个新文件( git-prompt.sh )。 提交介绍了这种变化,这也解释了理由,是af31a456 。

我仍然会建议您刚才源的版本git-completion.bash (或git-prompt.sh捆绑你的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'应该工作正常。



Answer 2:

升级到OSX 10.9小牛队之后,我不得不引用以下文件以获得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)")\$ '


Answer 3:

你应该

$酿造安装的bash的bash完成混帐

然后源 “$(BREW --prefix)的/ etc / bash_completion” 在你的.bashrc。



Answer 4:

继工作对我来说就像一个魅力:

运行在终端如下:

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

打开/创建的.bash_profile:

$ vi ~/.bash_profile

添加下列文件:

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"

最后,它源使用:

$ source ~/.bash_profile

这将解决问题bash: __git_ps1: command not found

此外,您的提示将变更为“OS”。 要改变“OS”到别的东西,修改出口PS1线“OS”的字符串。



Answer 5:

溶液为MacOS塞拉利昂和git版本2.10.1 <2017年2月6日>

步骤1:安装GIT中

你可以跳过这一步,如果你已经安装了最新的git。

从浏览器下载的git包https://git-scm.com/download/

注意:如果你安装curl [option] https://...选择下载,你必须确保你的系统支持SSL。 因此,对于新来者,从浏览器下载,并直接从Git的安装程序进行安装要容易得多。

Installation Verification:
  • 展会哪里是你的git目录中: which git
  • 显示该版本的混帐目前是: git --version目前的版本应该是2.10.1。

第2步:使用Git的配置文件添加到您的shell

  1. 打开你的shell配置文件:
    • nano ~/.bash_profilenano ~/.bashrc取决于您的修改是。
  2. 下面的代码添加到文件:
    • source /usr/local/git/contrib/completion/git-completion.bash
    • source /usr/local/git/contrib/completion/git-prompt.sh

注:git的安装位置从选择/目录改为USR /本地/ OSX升级到萨尔瓦多Capitain后,这就是为什么一些老的回答上面已经不在MacOS上塞拉利昂工作。

  1. 下面的代码添加到您的PS1配置:

    • 选项1:直接添加到您的PS1: export PS1='\w$(__git_ps1 "(%s)") > '

      我喜欢这种简单的方法,因为我已经知道了.git-completion.bash有我的主目录,我可以在它的前面加上其他提示格式。 这是我个人的提示,供您参考: export PS1='\t H#\! \u:\w$(__git_ps1 "{%s}") -->> ' export PS1='\t H#\! \u:\w$(__git_ps1 "{%s}") -->> '
    • 选项2:添加一个选择脚本

      如果[-f〜/ git的-completion.bash];  然后        出口PS1 = '\ W $(__ git_ps1 “(%S)”)>'  科幻 
  2. 保存并使用配置文件: source ~/.bash_profilesource ~/.bashrc

Now you should see the git prompt working properly and shows which branch you are in right now.


Answer 6:

升级到优胜美地,当我有同样的问题。

我不得不修改~/.bashrcsource /usr/local/etc/bash_completion.d/git-prompt.sh而不是旧的路径。

然后重新源的. ~/.bashrc . ~/.bashrc得到的效果。



Answer 7:

对于bash __git_ps1现在在git-prompt.sh发现/usr/local/etc/bash_completion.d我的酿造安装Git版本1.8.1.5



Answer 8:

这部作品在OS 10.8中的.bash_profile

if [ -f ~/.git-prompt.sh ]; then
  source ~/.git-prompt.sh
  export PS1='YOURNAME[\W]$(__git_ps1 "(%s)"): '
fi


Answer 9:

对于MacPorts的我不得不添加: source /opt/local/share/git-core/git-prompt.sh我./profile



Answer 10:

如果你希望使用自制软件升级Git和你已经让你的系统变成了过期一般(像我一样),你可能需要携带自制本身跟上时代的第一(按酿造更新:以下未跟踪工作树中的文件将被合并覆盖:感谢@克里斯- frisina)

首先把自制统一到当前版本

CD的/ usr /本地
混帐取起源
GIT中的复位 - 硬起源/主

然后更新的Git:

BREW升级混帐

问题解决了! ;-)



Answer 11:

至少在Xcode 6,你已经有git-completion.bash 。 这是Xcode的应用程序束的内侧。

只需添加到您的.bashrc:

source `xcode-select -p`/usr/share/git-core/git-completion.bash


Answer 12:

高塞拉利昂清洁液颜色!

没有下载。 没有啤酒。 没有的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" "\\\$ "'


Answer 13:

我知道这是不是一个真正的答案...

我曾与采购git-prompt.sh一些奇怪的问题,在我的.bashrc所以我开始寻找其他的解决方案。 这一个: http://www.jqno.nl/post/2012/04/02/howto-display-the-current-git-branch-in-your-prompt/不使用__git_ps1和作者声称它的工作原理也在Mac上(现在它完美的作品在我的Ubuntu和它很容易调整)。

我希望它能帮助!



Answer 14:

我做了git的枢纽上Udacity的课程,并有同样的问题。 这是我最后的代码,使是正常工作。

# Change command prompt
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

source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# '\u' adds the name of the current user to the prompt
# '\$(__git_ps1)' adds git-related stuff
# '\W' adds the name of the current directory
export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"

有用! https://i.stack.imgur.com/d0lvb.jpg



Answer 15:

  1. 下载文件git-prompt.shgit-completion.bash从这个混帐完成
  2. 重命名文件。
  3. 移动这些文件到你的主目录。
  4. 添加源文件到的.bash_profile

     source ~/git-completion0.bash source ~/git-prompt0.sh and four to trigger the code block. 


Answer 16:

这一个工作对我来说,它有彩色输出的git,并在提示文件是否已经修改/添加了,正确的烤到它的指标:

GIT_PS1_SHOWDIRTYSTATE=true

. /usr/local/Cellar/git/1.8.5.2/etc/bash_completion.d/git-completion.bash
. /usr/local/Cellar/git/1.8.5.2/etc/bash_completion.d/git-prompt.sh

PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

一定要使用正确的路径! 我用自制安装git的,使用brew list git来获取路径到您当前的安装。

将是很好,不要使用硬编码路径,但不知道怎么弄的路径,当前安装。

这里更多的相关信息: http://en.newinstance.it/2010/05/23/git-autocompletion-and-enhanced-bash-prompt/



Answer 17:

对于git的,有/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh 。 并请认准/etc/bashrc_Apple_Terminal了。

于是,我把这些在~/.bash_profile

if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh ]; then
  . /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
  export GIT_PS1_SHOWCOLORHINTS=1
  export GIT_PS1_SHOWDIRTYSTATE=1
  PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }__git_ps1 '\u:\w' '\\\$ '"
fi


文章来源: (Mac) -bash: __git_ps1: command not found