-bash:\uuu git\u ps1:未找到命令

-bash:\uuu git\u ps1:未找到命令,bash,shell,command,git-bash,ruby-2.0,Bash,Shell,Command,Git Bash,Ruby 2.0,我尝试安装Ruby 2.0。我的命令行urped,现在看起来如下所示: -bash: __git_ps1: command not found [11:58:28][whatever@whatever ~]$ $ curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git 我不知道如何消除uu git_ps1命令not found错误。我已经搜索了我的.bas

我尝试安装Ruby 2.0。我的命令行urped,现在看起来如下所示:

-bash: __git_ps1: command not found
[11:58:28][whatever@whatever ~]$ 
$ curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
我不知道如何消除uu git_ps1命令not found错误。我已经搜索了我的.bash_配置文件和我的.bashrc,看看它是否试图设置变量或其他东西,但没有看到任何东西。在~/.dotfiles/.bash\u提示符中,我可以找到提到的git_ps1。我完全替换了该文件的内容,注销并重新登录,但没有修复任何问题

我看到了,但我对命令行还很陌生,所以我把自己弄糊涂了

有什么想法吗?

运行以下命令:

-bash: __git_ps1: command not found
[11:58:28][whatever@whatever ~]$ 
$ curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
并将其添加到
~/.bashrc
的顶部:

source ~/.bash_git

重新登录到您的shell,您应该已经设置好了。

BASH有很多方法可以自动设置提示,为您提供良好的信息。通过设置
PS1
环境变量来设置提示。例如,如果我设置
PS1=“$”
我的提示符如下所示:

$ 
david@vegibank:/usr/bin$ 
david@vegibank:/usr/bin
$ 
信息量不大。我只知道命令行在提示我

但是,如果我设置了
PS1=\u@\h:\w$
,我的提示现在将如下所示:

$ 
david@vegibank:/usr/bin$ 
david@vegibank:/usr/bin
$ 
这说明了我是如何登录的(
\u
),我所在的机器(
\h
),以及我所在的目录(
\w
)。如果我使用git
git
,如果我所在的git分支也是我的提示符的一部分,那就太好了

这正是你的
.profile
、你的
.bashrc
文件、你的
.bash\u登录名
或你的
.bash\u profile
脚本所发生的事情。或者,一些系统管理员在
/etc/profile
中所做的操作

你可以做几件事。要么:

  • 下载缺少的
    \uuu git\u ps1
    ,并确保它位于
    $PATH
    环境变量中(由上述各种初始化文件组合设置)
  • 在任何正在执行的初始化文件中更改您的
    PS1
    环境变量(我相信它可能是
    .bash\u profile
只需将此添加为最后一行:

PS1="\u@\h:\w\n$ "
添加的
\n
在以下行打印美元符号提示,如下所示:

$ 
david@vegibank:/usr/bin$ 
david@vegibank:/usr/bin
$ 
我喜欢这样做,因为提示可能会变得很长,当提示长度超过30到50个字符时,编辑命令行会变得很棘手。否则,它几乎是大多数用户使用的标准提示。您可以在中查看有关设置BASH提示的更多信息。(在该页面上搜索“提示”一词)

如果您觉得有点困惑,很高兴您没有使用Kornshell。我使用Kornshell,为了得到与之相同的提示
PS1=\u@\h:\w\n$
does,我将提示设置为:

export PS1='$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'

在您的系统中搜索
git提示符.sh
,您需要
source
才能使用
\uuu git\u ps1
功能。在Arch中,它当前位于
/usr/share/git/completion/git提示符.sh
。添加

source /path/to/git-prompt.sh
如果您不确定在哪里,请将其添加到
~/.bashrc


如果您安装了
locate
,您可以使用它来查找
git prompt.sh
文件,但您可能需要首先以root用户身份运行
updatedb

从2019年起,在安装
git
包时应安装提示助手功能,可以在
/usr/lib/git core/git sh prompt
上找到该功能

如果未加载,请安装
bash completion
软件包并查看
~/.bashrc

在我的情况下,我不得不取消注释:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
打开一个新的外壳,一切都很好


根本原因是新安装时没有正确设置“bash completion”。

引用
/usr/lib/git core/git sh提示符

# This script allows you to see repository status in your prompt.
#
# To enable:
#
#    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
#    2) Add the following line to your .bashrc/.zshrc:
#        source ~/.git-prompt.sh
#    3a) Change your PS1 to call __git_ps1 as
#        command-substitution:
#        Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#        ZSH:  setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
#        the optional argument will be used as format string.
#    3b) Alternatively, for a slightly faster prompt, __git_ps1 can
#        be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
#        with two parameters, <pre> and <post>, which are strings
#        you would put in $PS1 before and after the status string
#        generated by the git-prompt machinery.  e.g.
#        Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
#          will show username, at-sign, host, colon, cwd, then
#          various status string, followed by dollar and SP, as
#          your prompt.
#        ZSH:  precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
#          will show username, pipe, then various status string,
#          followed by colon, cwd, dollar and SP, as your prompt.
#        Optionally, you can supply a third argument with a printf
#        format string to finetune the output of the branch status
#此脚本允许您在提示符中查看存储库状态。
#
#要启用:
#
#1)将此文件复制到某处(例如~/.git prompt.sh)。
#2)在.bashrc/.zshrc中添加以下行:
#source~/.git-prompt.sh
#3a)将您的PS1更改为将_git_PS1作为
#命令替换:
#Bash:PS1='[\u@\h\W$(\u git\u PS1”(%s)”)]\$'
#ZSH:setopt提示符_SUBST;PS1='[%n@%m%c$(%s)]\$'
#可选参数将用作格式字符串。
#3b)或者,对于稍微快一点的提示,_git_ps1可以
#用于Bash中的PROMPT_命令或Zsh中的precmd()
#具有两个参数,和,它们是字符串
#您可以在状态字符串前后输入$PS1
#由git提示机制生成。例如
#Bash:PROMPT\u命令=“\uu git\u ps1”\u@\h:\w”“\\\\$”
#将显示用户名、at符号、主机、冒号、cwd,然后
#各种状态字符串,后跟美元和SP,如下所示
#你的提示。
#ZSH:precmd(){{uuu git_ps1“%n”:%~$”|%s}
#将显示用户名、管道,然后是各种状态字符串,
#然后是冒号、cwd、美元和SP,作为提示。
#或者,您可以使用printf提供第三个参数
#格式化字符串以微调分支状态的输出

遵循这些步骤应该可以解决您的问题

我简单地用

sudo-apt-install-git

出现这种情况是因为没有安装git,因此没有定义环境变量。

您使用的是哪一版本的git?看看git版本1.7.10.2(Apple git-33)解决方法:Blake,我得到以下结果:curl:(3)格式错误如果您在本地安装了git(至少在Fedora上),git-prompt.sh脚本包含在git发行版中,位于
/usr/share/git-core/contrib/completion/git-prompt.sh
@Arch下的情况也差不多:
/usr/share/git/completion/git-prompt.sh
在Debian Jessie上,它被称为
git-sh-prompt
,位于
/usr/lib/git-core/git-sh-prompt
我补充道这是我的BP的最后一行,至少现在没有中断。我会继续努力