Closed atupal closed 11 years ago
there are the code HalloweenBash generate:
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\h:\W \u\$(parse_git_branch)$ "
Hi @atupal,
I apologize, but I don't understand your question. It's possible your environment has different dependencies which you may need to include.
As I understand my code, it shows you the current git branch if your current directory uses git. You get no git branch information if your current directory does not use git.
Let me know if you have any questions.
Thanks, -Rex
I find the problem in my code: Because I use the follow code:
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
git_branch=" \[\e[0;33m\]$(parse_git_branch)\[\e[m\] "
export PS1="\h:\W \u\$git_branch$ "
so after I source .bashrc
the $git_branch
become a fixed string but not raw string after initial. (because i use the "
);
And it work after I change the "
to'
;
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
git_branch=' \[\e[0;33m\]$(parse_git_branch)\[\e[m\] '
export PS1="\h:\W \u\ $git_branch$ "
thx! I am sorry for my careless ...
@atupal Great, glad it works!
You use a shell fucntion in PS1 But when you "cd" to a git repo dir, you need source ~/.bashrc to go the git branch display in the command prompt. and then you cd to other dir(not a git repo), and the branch is staill in the bash prompt...
Is any error in my environ (arch-linux , bash) ? I then use PROMPT_COMMAND solve this:
thx
ptw: awesome project !