From 8b96472116db7167aca29c63204e2d0d4c8b7985 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sat, 22 Dec 2012 12:52:06 -0600 Subject: [PATCH] .bashrc: Use __git_ps1() in $PS1 Use __git_ps1() to display current branch info in bash prompt (PS1). * Never show this for the $HOME (dotfiles) repo since it would get obnoxious. * Check a (custom) `git config` variable to allow repo-specific exclusion of __git_ps1() handling. --- .bashrc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index 3ba2059..d1c375d 100644 --- a/.bashrc +++ b/.bashrc @@ -192,7 +192,17 @@ prompt_compact() { } prompt_color() { - PS1="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] " + # If git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info. + # Never show branch info for $HOME (dotfiles) repo. + # Use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true` + if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then + PS_GIT='$(test -n "$(__git_ps1 %s)" && + test "$(git rev-parse --show-toplevel)" != "$HOME" && + test "$(git config --bool bash.hidePrompt)" != "true" && + __git_ps1 "{\[\033[0;100m\]%s\[\033[0;90m\]}")' + export GIT_PS1_SHOWDIRTYSTATE=1 + fi + PS1="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_GIT}${PS_P}\[\033[0m\] " PS2="> " } -- 2.45.2