Macos (Mac)-bash:\uuu git\u ps1:未找到命令
我正在试图更改终端中的命令提示符。我不断得到错误:Macos (Mac)-bash:\uuu git\u ps1:未找到命令,macos,git,terminal,ps1,Macos,Git,Terminal,Ps1,我正在试图更改终端中的命令提示符。我不断得到错误: -bash:\uu git\u ps1:未找到命令 我只需按原样在终端中键入:\uuu git\u ps1就可以了。我也在.bash\u配置文件中试用过 if [ -f ~/.git-completion.bash ]; then source ~/.git-completion.bash export PS1='[\W]$(__git_ps1 "(%s)"): ' fi 正如你可能看到/告诉我的,是的,我确实安装了自动完成功能,它确
-bash:\uu git\u ps1:未找到命令
我只需按原样在终端中键入:\uuu git\u ps1
就可以了。我也在.bash\u配置文件中试用过
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
正如你可能看到/告诉我的,是的,我确实安装了自动完成功能,它确实工作得很好
我遇到了这样一个问题:“它给出了代码
alias\uu git\u ps1=“git branch 2>/dev/null | grep'*'| sed's/*\(.*)/(\1)/”
所以我把它添加到我的.bash\u档案中
,希望它能改变一些东西。嗯,的确如此。它只是改变了错误输出
以下是.bash\u配置文件
,其中包括:
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):没有这样的文件或目录
注意:我还将别名移到了源代码下方,没有任何区别。我有git版本1.7.12.1
这应该是一个简单的改变。有人能帮我吗
编辑10/13/12
不,我当然不想自己定义_ugit_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日-由Mark Longair解决(如下)
下面的代码在.bash\u配置文件中对我有效,而其他人则没有
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
export PS1='Geoff[\W]$(__git_ps1 "(%s)"): '
fi
您已经从master
安装了git completion.bash的版本-在git的开发历史中,这是在提交之后,将\uu git\u ps1
函数从完成功能拆分为一个新文件(git prompt.sh
)。引入此更改的提交(解释了基本原理)是
我仍然建议您只需获取与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
。。。并将以下行添加到您的~/.bash\u配置文件中:
source ~/.git-prompt.sh
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
然后,您的PS1
变量中包含\uuu git\u PS1“%s”
应该可以正常工作。\uuu git\u PS1 for bash现在可以在我的brew安装的git版本1.8.1.5的/usr/local/etc/bash\u completion.d中的git-prompt.sh中找到它。我知道这不是一个真正的答案
我在.bashrc中查找git-prompt.sh时遇到了一些奇怪的问题,所以我开始寻找其他解决方案。这一个:不使用_git_ps1,作者声称它在Mac上也能工作(现在它在我的Ubuntu上工作得很好,而且很容易调整)
我希望有帮助 这在.bash_配置文件的OS 10.8中有效
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
export PS1='YOURNAME[\W]$(__git_ps1 "(%s)"): '
fi
在升级到OSX 10.9 Mavericks之后,我必须引用以下文件,以使git shell命令完成和git提示符再次工作
从my.bash_档案或类似档案:
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)")\$ '
这一个对我很有用,它对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
获取当前安装的路径
最好不要使用硬编码路径,但不知道如何获取当前安装的路径
这里有更多信息:对于macports,我必须添加:source/opt/local/share/git core/git prompt.sh
到我的个人资料中
$brew安装bash bash完成git
然后在你的.bashrc中输入“$(brew--prefix)/etc/bash_completion”。如果你希望使用自制软件升级Git,而你的系统总体上已经过时(正如我所做的那样),你可能需要先更新自制软件本身(根据Thank@chris frisina)
首先将自制软件与当前版本保持一致
cd/usr/local
git获取来源
git重置--硬原点/主原点
然后更新Git:
brew升级git
问题解决了!;-) 升级到约塞米蒂时,我也遇到了同样的问题
我只需要将~/.bashrc
修改为source/usr/local/etc/bash\u completion.d/git prompt.sh,而不是原来的路径
然后重新编写~/。bashrc
以获得效果。至少在使用Xcode 6时,您已经有了git completion.bash
。它在Xcode应用程序包中
只需将此添加到您的.bashrc:
source `xcode-select -p`/usr/share/git-core/git-completion.bash
对于git,有/Applications/Xcode.app/Contents/Developer/usr/share/git core/git prompt.sh
。请同时查看/etc/bashrc\u Apple\u终端
所以,我把它们放在~/.bash_profile
中:
source ~/.git-prompt.sh
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
以下内容对我来说很有魅力:
在终端中运行以下命令:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
打开/创建bash_配置文件:
$ 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:\uu git\u ps1:未找到命令的问题
您的提示也将变为“操作系统”。要将“os”更改为其他内容,请修改导出PS1行中的“os”字符串 MacOS Sierra和git版本2.10.1的解决方案
步骤1:安装Git
如果已经安装了最新的git,则可以跳过此步骤。
从浏览器下载git包
注意:如果使用curl[选项]安装https://...
选项下载时,您必须确保您的系统支持SSL。所以对于新手来说,从浏览器下载并直接从git安装程序安装要容易得多
安装验证:
- 显示git目录的位置:
哪个git
- 显示您的git currentl的版本
source ~/git-completion0.bash
source ~/git-prompt0.sh
and four to trigger the code block.
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" "\\\$ "'
if [ -f /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash ]; then
. /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
fi
source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
GIT_PROMPT_ONLY_IN_REPO=1
source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi