为什么PS1没有用git分支名称更新? [英] Why PS1 is not updated with the git branch name?

查看:138
本文介绍了为什么PS1没有用git分支名称更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PS1="\\w (`git branch | grep '^*' | cut -b 3-100`)$ "

我将PS1设置为如上所述,但是在我使用 git checkout 更改分支或使用 cd .该如何解决?

I set my PS1 as above, but it will not update the branch name in the prompt after I change the branch with git checkout, or change the repository with the cd. How to fix this?

推荐答案

设置(一次)设置 PS1 而不是显示提示时,将对反引号引起来的位进行评估.使用单引号将扩展保存为后一个事件:

The backtick-quoted bit is evaluated when PS1 is set (once), not when the prompt is displayed. Use single quotes to save the expansion for the latter event:

PS1='\w (`git branch | grep "^*" | cut -b 3-100`)$ '

这篇关于为什么PS1没有用git分支名称更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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