View difference between Paste ID: PnAhtwVU and D6WGW455
SHOW: | | - or go back to the newest paste.
1-
diff --git a/prompt b/prompt
1+
diff --git a/.bashrc b/.bashrc
2
index 02a3faa..e9ab47a 100644
3
--- a/prompt
4
+++ b/prompt
5
@@ -35,7 +35,7 @@ PS1_GIT_BIN=$(which git 2>/dev/null)
6
 function prompt_command {
7
     local PS1_GIT=
8
     local PS1_VENV=
9
-    local GIT_BRANCH=
10
+    local CURRENT_GIT_BRANCH=
11
     local GIT_DIRTY=
12
     local PWDNAME=$PWD
13
     local VIRTUAL_ENV=${VIRTUAL_ENV-}
14
@@ -56,9 +56,9 @@ function prompt_command {
15
             # 'git repo for dotfiles' fix: show git status only in home dir and other git repos
16
             if [[ "${CUR_DIR}" != "${HOME}" ]] || [[ "${PWD}" == "${HOME}" ]]; then
17
                 # get git branch
18
-                GIT_BRANCH=$($PS1_GIT_BIN symbolic-ref HEAD 2>/dev/null)
19
-                if [[ ! -z $GIT_BRANCH ]]; then
20
-                    GIT_BRANCH=${GIT_BRANCH#refs/heads/}
21
+                CURRENT_GIT_BRANCH=$($PS1_GIT_BIN symbolic-ref HEAD 2>/dev/null)
22
+                if [[ ! -z $CURRENT_GIT_BRANCH ]]; then
23
+                    CURRENT_GIT_BRANCH=${CURRENT_GIT_BRANCH#refs/heads/}
24
 
25
                     # get git status
26
                     local GIT_STATUS=$($PS1_GIT_BIN status --porcelain 2>/dev/null)
27
@@ -69,7 +69,7 @@ function prompt_command {
28
     fi
29
 
30
     # build b/w prompt for git and virtual env
31
-    [[ ! -z $GIT_BRANCH ]] && PS1_GIT=" (git: ${GIT_BRANCH})"
32
+    [[ ! -z $CURRENT_GIT_BRANCH ]] && PS1_GIT=" (git: ${CURRENT_GIT_BRANCH})"
33
     [[ ! -z $VIRTUAL_ENV ]] && PS1_VENV=" (venv: ${VIRTUAL_ENV#$WORKON_HOME})"
34
 
35
     # calculate prompt length
36
@@ -90,11 +90,11 @@ function prompt_command {
37
 
38
     if $color_is_on; then
39
         # build git status for prompt
40
-        if [[ ! -z $GIT_BRANCH ]]; then
41
+        if [[ ! -z $CURRENT_GIT_BRANCH ]]; then
42
             if [[ -z $GIT_DIRTY ]]; then
43
-                PS1_GIT=" (git: ${color_green}${GIT_BRANCH}${color_off})"
44
+                PS1_GIT=" (git: ${color_green}${CURRENT_GIT_BRANCH}${color_off})"
45
             else
46
-                PS1_GIT=" (git: ${color_red}${GIT_BRANCH}${color_off})"
47
+                PS1_GIT=" (git: ${color_red}${CURRENT_GIT_BRANCH}${color_off})"
48
             fi
49
         fi
50
 
51
@@ -123,9 +123,21 @@ function prompt_command {
52
 
53
     # set title
54
     echo -ne "\033]0;${USER}@${HOSTNAME}:${PWDNAME}"; echo -ne "\007"
55
+
56
+    if [ -n "$CURRENT_GIT_BRANCH" ]; then
57
+        GIT_BRANCH="$CURRENT_GIT_BRANCH";
58
+    else
59
+        unset GIT_BRANCH
60
+    fi
61
+    export GIT_BRANCH
62
+    GIT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
63
+    if [ -z "$GIT_ROOT" ]; then
64
+        unset GIT_ROOT
65
+    fi
66
+    export GIT_ROOT
67
 }
68
 
69
 # set prompt command (title update and color prompt)
70
 PROMPT_COMMAND=prompt_command
71
 # set new b/w prompt (will be overwritten in 'prompt_command' later for color prompt)
72
-PS1='\u@\h:\w\$ '
73
+PS1='\u@\h:\w\$ '
74
\ No newline at end of file