Browse code

Added some git prompt text when not on a branch

Nicolas Viennot authored on 01/06/2012 at 10:19:59
Showing 1 changed files
... ...
@@ -1,8 +1,17 @@
1 1
 # get the name of the branch we are on
2 2
 function git_prompt_info() {
3 3
   [[ "$GIT_PROMPT_DISABLED" != "" ]] && return
4
-  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
5
-  echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(git_prompt_status)$ZSH_THEME_GIT_PROMPT_SUFFIX"
4
+  ref=$(git symbolic-ref HEAD 2>&1)
5
+  if [[ $? == 0 ]]; then
6
+    echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(git_prompt_status)$ZSH_THEME_GIT_PROMPT_SUFFIX"
7
+    return
8
+  fi
9
+
10
+  if [[ $ref =~ "Not a git repository" ]]; then
11
+    return
12
+  fi
13
+
14
+  echo "${ZSH_THEME_GIT_PROMPT_PREFIX}no-branch$ZSH_THEME_GIT_PROMPT_UNMERGED$ZSH_THEME_GIT_PROMPT_SUFFIX"
6 15
 }
7 16
 
8 17
 function disable_git_prompt_info() {