Fixed some typos
[git_nutshell_guides.git] / _git_ps1
blobac702c7c8e3af04c45f8fd8e25d1172869a91f68
1 function _git_ps1()
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
6         local git_dir rel br
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; }
13         rel=${rel%\/}
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)
18         br=${br#refs/heads/}
19         br=${br:-HEAD}
21         # path to top dir of git repository
22         loc=${PWD%/$rel}
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}# "
30         else 
31                 echo "$br:${loc/*\/}${rel:+/$rel}> "
32         fi
35 ## bash:
36 ## set PS1 only if we are in interactive shell (PS1 is set)
37 #    [ "$PS1" ] && PS1='$(_git_ps1 "\u@\h:\w> ")'
39 ## zsh:
40 #       function precmd() {
41 #               PS1=`_git_ps1 '%m:%~%# '`
42 #       }
43 # vim:filetype=sh