如何在bash(mac)命令行首加入git标示呢

2013-11-06 17:38:06 +08:00
 tedd
我看到有些bash能命令首能显示git的标示

(master)$
(master*)$ 代表git有变化了

我知道是通过修改.bash_profile实现的,但要怎么改呢
$sudo vi ~/.bash_profile
4381 次点击
所在节点    问与答
9 条回复
panxianhai
2013-11-06 17:39:44 +08:00
pantaovay
2013-11-06 17:42:06 +08:00
@panxianhai 同意楼上
ShadowStar
2013-11-06 17:44:56 +08:00
tedd
2013-11-06 19:19:23 +08:00
@ShadowStar 感谢,但没有任何变动情况下也是显示的[master*],而有改动后也是这样,没有变化
horx
2013-11-06 19:47:56 +08:00
这个可以满足你的要求。

http://gist.github.com/horx/7334816
ivenvd
2013-11-06 19:49:54 +08:00
用 Fish 吧。
tedd
2013-11-06 20:35:41 +08:00
@horx 用了后terminal用不了了...
Last login: Wed Nov 6 20:31:49 on ttys000

[Process completed]

正在搜索如何重置terminal...
tedd
2013-11-06 20:50:34 +08:00
最后还是用了zsh...
zeroday
2014-07-27 20:10:10 +08:00
bash也可以的,查阅了一些资料,需要 __git_ps1

OS X

在 ~/.bash_profile 中添加

if [ -f $(xcode-select -p)/usr/share/git-core/git-completion.bash ]; then
. $(xcode-select -p)/usr/share/git-core/git-completion.bash
. $(xcode-select -p)/usr/share/git-core/git-prompt.sh
fi

Linux

$ curl -o ~/.git-prompt.sh \
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
随后在 ~/.bash_profile 中 source

[[ -f ~/.git-prompt.sh ]] && . ~/.git-prompt.sh
最后 ~/.bashrc 中编辑你的 PS1,在其中某处添加 $(__git_ps1) 即可。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/88290

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX