-->

-bash:__git_ps1:命令未找到(-bash: __git_ps1: command no

2019-07-21 12:08发布

我试图安装Ruby 2.0。 urped现在我的命令行如下所示:

-bash: __git_ps1: command not found
[11:58:28][whatever@whatever ~]$ 

我还没有线索如何摆脱没有发现错误__git_ps1命令。 我搜索我的.bash_profile和我的.bashrc,看看它试图设置一个变量或东西,我没有看到任何东西。 我能找到提到git_ps1唯一的地方是在〜/ .dotfiles / .bash_prompt。 我替换该文件的内容完全注销并重新登录,并修复什么。

我看到了这个 ,但我很新的,所以我只是困惑自己命令行。

有任何想法吗?

Answer 1:

BASH有自动设置你的提示,给你不错的信息的方式整体转换。 您可以通过设置设置提示PS1环境变量。 例如,如果设置了PS1="$ "我的提示会是这样的:

$ 

不要太丰富。 我能说的是,在命令行提示我。

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

david@vegibank:/usr/bin$ 

这告诉我,我怎么登录(中\u ),机器我到( \h ),而我(的就是目录\w )。 如果我用git ,如果混帐分支我在也是我提示的一部分这将是很好。

这到底是怎么回事与您的.profile ,你.bashrc文件,您的.bash_login或您.bash_profile脚本。 或者说,什么样的一些系统管理员没有在/etc/profile

有一对夫妇的事情可以做。 或者:

  • 下载缺少的__git_ps1 ,并确保它在你的$PATH环境变量(这是由上面提到的各种初始化文件的组合集)
  • 改变你的PS1在正在执行的任何初始化文件中的环境变量(我认为这是可能.bash_profile

只需添加这是最后一行:

PS1="\u@\h:\w\n$ "

所添加的\n打印下面这样就行了美元符号提示:

david@vegibank:/usr/bin
$ 

我喜欢这样做,因为提示可以得到相当长,当提示长于30到50个字符编辑命令行变得棘手。 否则,这几乎是大多数用户使用标准的提示。 你可以看到更多的有关设置BASH提示手册页 。 (搜索单词提示该网页上)。

如果你觉得有点混乱,是你不使用Kornshell高兴。 我用Kornshell,并获得相同的提示PS1=\u@\h:\w\n$呢,我把我的提示是:

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


Answer 2:

运行以下命令:

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

而这增加的顶部你~/.bashrc

source ~/.bash_git

重新登录到你的shell,你应该设置。



Answer 3:

在系统中搜索一个git-prompt.sh ,你需要source的是,对于__git_ps1功能可用。 在凯旋门,它是目前位于/usr/share/git/completion/git-prompt.sh 。 加

source /path/to/git-prompt.sh

一些合适的shell脚本。 如果你不确定在哪里,它添加到你~/.bashrc

如果你已经locate安装,你可以用它来找到git-prompt.sh文件,但您可能需要运行updatedb为root用户。



Answer 4:

如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

并打开一个新的外壳,和一切都很好。

根本原因是“庆典 - completion`没有被正确设置在首位上全新安装。



Answer 5:

从引用/usr/lib/git-core/git-sh-prompt

# 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

按照这些步骤应该解决您的问题!



文章来源: -bash: __git_ps1: command not found