如何扩展__git_ps1?我收到“未找到命令”
当我不在 git 目录中时,__git_ps1
返回(unknown)
,而不是返回任何内容。这是一个我不太满意的改变。所以我试图扩展它以恢复旧的行为。因此,我将其添加到我的 ~/.bashrc
中,并确保 /etc/bash_completion
在它之前获取:
__git_silent_ps1() {
local b='$(__git_ps1 " (%s)")'
if ["$b" != " ((unknown))"]; then
echo -n $b
fi
}
但是当我使用 __git_silent_ps1
时在我的提示定义中,我得到:
-bash: [$(__git_ps1 " (%s)"): command not found
当我在提示定义中使用 __git_ps1
时,我没有收到该错误,但它显示了分支。知道为什么我会收到错误以及如何修复它吗?
__git_ps1
returns (unknown)
instead of nothing when I am not in a git directory. That's a change I'm not too happy with. So I am trying to extend it to get the old behaviour back. So, I added this in my ~/.bashrc
and made sure that /etc/bash_completion
is sourced before it:
__git_silent_ps1() {
local b='$(__git_ps1 " (%s)")'
if ["$b" != " ((unknown))"]; then
echo -n $b
fi
}
But when I use __git_silent_ps1
in my prompt definition, I get:
-bash: [$(__git_ps1 " (%s)"): command not found
When I just use __git_ps1
in my prompt definition I don't get that error but it displays the branch. Any idea why I am getting the error and how I can fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如不应该写
rmsomefile.txt
一样,也不应该写["$b"
。Just as one doesn't write
rmsomefile.txt
, one shouldn't write["$b"
.