From: Robin Rosenberg Date: Thu, 2 Nov 2006 21:18:32 +0000 (+0000) Subject: Bash snippet to show branch and patch in bash prompt X-Git-Tag: v0.14.3~441 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/2f5e43aab8d29b746a8e21597a5032eb77be1612 Bash snippet to show branch and patch in bash prompt Modified according to Eran Tromer's suggestions. Also added some personal preference to the default PS1 but people should really adapt this to their needs. Signed-off-by: Robin Rosenberg --- diff --git a/contrib/stgbashprompt.sh b/contrib/stgbashprompt.sh new file mode 100755 index 0000000..16bb39b --- /dev/null +++ b/contrib/stgbashprompt.sh @@ -0,0 +1,16 @@ +# modify PS1 to your preference and include this file in your bashrc +# or copy to /etc/bash_completions.d. + +if [ "$PS1" ]; then + function __prompt_git() + { + local git_dir ref br top; + git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return + ref=$(git-symbolic-ref HEAD 2> /dev/null) || return + br=${ref#refs/heads/} + top=$(cat $git_dir/patches/$br/current 2>/dev/null) \ + && top="/$top" + echo "[$br$top]" + } + PS1='\u@\h:$(__prompt_git)\W\$ ' +fi