(Mac) -bash: __git_ps1: 命令未找到 [英] (Mac) -bash: __git_ps1: command not found

查看:33
本文介绍了(Mac) -bash: __git_ps1: 命令未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改终端中的命令提示符.我不断收到错误:

I'm trying to change my command promt in terminal. I keep getting the error:

-bash: __git_ps1: 命令未找到

我只是通过在终端中按原样输入它来尝试它:__git_ps1.我也在 .bash_profile

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!

我遇到了这个问题:PS1 环境变量不起作用在 mac 上 " 给出了代码

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)/'"

所以我将它添加到我的 .bash_profile 中,希望它能改变一些东西.嗯,确实如此.它只是改变了错误输出.

So I add it to my .bash_profile hoping that it will change something. Well, it did. It just changed the error output.

这是带有附加内容的 .bash_profile:

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): 没有那个文件或目录

注意:我还将别名移到了源下面,没有任何区别.我有 git 版本 1.7.12.1

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

This should be a simple change. Can someone please help me?

编辑 10/13/12

不,我绝对不想自己定义 __git_ps1,只是想看看这样做是否会被识别.是的,我已经安装了 .git-completion.bash 文件.这是我如何在我的机器上自动完成.

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 然后列出 .git-completion.bash 文件.

A ls -la then lists the .git-completion.bash file.

编辑 10/13/12 - 由 Mark Longair 解决(下)

以下代码在 .bash_profile 中对我有用,而其他代码则没有...

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

推荐答案

您已经安装了 mastergit-completion.bash 版本 - 在 git 的开发历史中这是在将 __git_ps1 函数从完成功能拆分为一个新文件 (git-prompt.sh) 之后的提交.引入此更改的提交(解释了基本原理)是 af31a456.

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.

我仍然建议您只获取与您的 git 安装捆绑在一起的 git-completion.bash(或 git-prompt.sh)版本.

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.

但是,如果出于某种原因,您仍然希望通过使用从 master 单独下载的脚本来使用此功能,您应该类似地下载 git-prompt.sh:>

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

... 并将以下行添加到您的 ~/.bash_profile:

... and add the following line to your ~/.bash_profile:

source ~/.git-prompt.sh

那么包含 __git_ps1 '%s'PS1 变量应该可以正常工作.

Then your PS1 variable that includes __git_ps1 '%s' should work fine.

这篇关于(Mac) -bash: __git_ps1: 命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆