command line - Git branch name in bash shell don't disappear on non git directories - Ask Ubuntu
i'm using this guide add git branch name ps1 variable. changed little bit, leave current prompt theme , add green background git branch name.
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export ps1="$ps1\e[30;48;5;82m$(parse_git_branch)\e[0m \[\033[00m\]"
looks works, when leave directory, git branch name stays. , if run terminal in not git directory, , cd git, can't see name of branch. when open terminal tab, see it.
i use guake terminal bash shell.
this happening because prompt being set value of parse_git_branch
when prompt set, need run function each time run.
you need put \
before $(parse_git_branch)
dollar hidden when prompt set not run. when prompt executed dollar visible , command in brackets run showing right value folder in.
export ps1="$ps1\e[30;48;5;82m\$(parse_git_branch)\e[0m \[\033[00m\]"
this explaind in bash docs on 2nd paragraph of page http://www.tldp.org/howto/bash-prompt-howto/x279.html
another useful trick here run /bin/bash -x
, try , shows more of happening.
Comments
Post a Comment