简体   繁体   中英

Bash Git prompt does not hide outside of repository

my (simplified) PS1: export PS1="\\A \\w\\ $(__git_ps1) \\$ "

prompt: 16:08-~/dev (master) $

This is all good and it shows branch name when there is one. But outside of the repo it still shows (master) instead of . I've been searching like crazy but can't find the answer.

What environment information do you need to help me solve this? I'm not that well versed in Bash yet. There has to be something off. Or is there something wrong with my Git version?

16:08 ~/dev (master) $ git --version
git version 2.7.4

Thanks in advance for taking a look at this!

You are running __git_ps1 once , when you define PS1 , and using the same value for every prompt later on. You want to run that command every time the prompt is displayed, so you need to escape the $ to prevent command substitution from happening immediately.

export PS1='\A \w\ $(__git_ps1) \$ '

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM