我想在我的gnome的终端里面提示分支,但是如何让PS1执行一个函数?
我想让我的PS1显示git 分支,但是每次get_git_branch好像执行了一次,就一直是那个分支,我想每次PS1打印的时候都能执行一次这个函数该怎么办?
function get_git_branch()
{
branch__=
git branch &> /dev/null
if [ $? -eq 0 ]; then
branch__=`git branch --no-color | sed -ne 's/^\* \(.*\)$/\1/1p'`
else
branch__="NORMAL"
fi
echo -n $branch__
}
export PS1="[\w]\n\[\033[1;36m\]\u\[\033[1;33m\]->$(get_git_branch)\[\033[0m\]"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个完整的.bashrc例子
ps. 建议用 zsh 代替
bash
, 然后使用 oh-my-zsh 美化zsh
, 有众多插件和theme选择,都支持git branch提示。