Skip to content

Commit 4153ec7

Browse files
committed
Made gitstatus variables for symbols_ahead, symbols_behind and symbols_prehash configurable via git-prompt-colors.sh
Fixes magicmonty#51 The new variables are: ```bash GIT_STATUS_SYMBOLS_AHEAD GIT_STATUS_SYMBOLS_BEHIND GIT_STATUS_SYMBOLS_PREHASH ```
1 parent 557d395 commit 4153ec7

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

git-prompt-colors.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
GIT_PROMPT_STAGED="${Red}" # the number of staged files/directories
88
GIT_PROMPT_CONFLICTS="${Red}" # the number of files in conflict
99
GIT_PROMPT_CHANGED="${Blue}" # the number of changed files
10-
GIT_PROMPT_REMOTE=" " # the remote branch name (if any)
10+
GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind
1111
GIT_PROMPT_UNTRACKED="${Cyan}" # the number of untracked files/dirs
1212
GIT_PROMPT_STASHED="${BoldBlue}" # the number of stashed files/dir
1313
GIT_PROMPT_CLEAN="${BoldGreen}" # a colored flag indicating a "clean" repo
14+
15+
# Please do not add colors to these symbols
16+
GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin"
17+
GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin"
18+
GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found

gitprompt.sh

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ function git_prompt_config()
7777
GIT_PROMPT_UNTRACKED="${Cyan}"
7878
GIT_PROMPT_STASHED="${BoldBlue}"
7979
GIT_PROMPT_CLEAN="${BoldGreen}"
80+
81+
# Please do not add colors to these symbols
82+
GIT_PROMPT_SYMBOLS_AHEAD="↑·"
83+
GIT_PROMPT_SYMBOLS_BEHIND="↓·"
84+
GIT_PROMPT_SYMBOLS_PREHASH=":"
8085
fi
8186

8287
# Various variables you might want for your PS1 prompt instead

gitstatus.sh

+44-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,51 @@
99
count_lines() { echo "$1" | egrep -c "^$2" ; }
1010
all_lines() { echo "$1" | grep -v "^$" | wc -l ; }
1111

12+
if [ -z "${__GIT_PROMPT_DIR}" ]; then
13+
SOURCE="${BASH_SOURCE[0]}"
14+
while [ -h "${SOURCE}" ]; do
15+
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
16+
SOURCE="$(readlink "${SOURCE}")"
17+
[[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}"
18+
done
19+
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
20+
fi
21+
22+
if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then
23+
for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do
24+
for pfx in '.' '' ; do
25+
file="$dir/${pfx}git-prompt-colors.sh"
26+
if [[ -f "$file" ]]; then
27+
__GIT_PROMPT_COLORS_FILE="$file"
28+
break 2
29+
fi
30+
done
31+
done
32+
fi
33+
34+
# if the envar is defined, source the file for custom colors
35+
if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then
36+
source "$__GIT_PROMPT_COLORS_FILE"
37+
fi
38+
1239
# change those symbols to whatever you prefer
13-
symbols_ahead='↑·'
14-
symbols_behind='↓·'
15-
symbols_prehash=':'
40+
if [[ -n "${GIT_PROMPT_SYMBOLS_AHEAD}" ]]; then
41+
symbols_ahead="${GIT_PROMPT_SYMBOLS_AHEAD}"
42+
else
43+
symbols_ahead='↑·'
44+
fi
45+
46+
if [[ -n "${GIT_PROMPT_SYMBOLS_BEHIND}" ]]; then
47+
symbols_behind="${GIT_PROMPT_SYMBOLS_BEHIND}"
48+
else
49+
symbols_behind='↓·'
50+
fi
51+
52+
if [[ -n "${GIT_PROMPT_SYMBOLS_PREHASH}" ]]; then
53+
symbols_prehash=':'
54+
else
55+
symbols_prehash="${GIT_PROMPT_SYMBOLS_PREHASH}"
56+
fi
1657

1758
gitsym=`git symbolic-ref HEAD`
1859

0 commit comments

Comments
 (0)