3 # 'git_dir' is absolute path to git repository
4 # 'rel' is path relative to top dir in repository
5 # 'br' is current branch name, or 'HEAD' if we are on detached HEAD
8 # first call to git-rev-parse also checks if we are inside git
9 # repository; if we are not in git repository, use default prompt,
10 # provided as an argument
11 rel=$(git rev-parse --show-prefix 2>/dev/null) || \
12 { echo "$@" ; return; }
15 # get branch name, strip 'refs/heads/' prefix,
16 # and use 'HEAD' for detached HEAD (no branch name)
17 br=$(git symbolic-ref HEAD 2>/dev/null)
21 # path to top dir of git repository
24 # the following code is important only if you use StGit,
25 # to note if you are on StGit controlled branch;
26 # use second part of conditional if you don't use StGit
27 git_dir=$(git rev-parse --git-dir)
28 if [ "$br" -a -e "$git_dir/patches/$br" ]; then
29 echo "$br:${loc/*\/}${rel:+/$rel}# "
31 echo "$br:${loc/*\/}${rel:+/$rel}> "
36 ## set PS1 only if we are in interactive shell (PS1 is set)
37 # [ "$PS1" ] && PS1='$(_git_ps1 "\u@\h:\w> ")'
41 # PS1=`_git_ps1 '%m:%~%# '`