Skip to content

Commit 0b4a965

Browse files
committed
Merge pull request #72 from aks/master
Added git_prompt_reset
2 parents 8826ec6 + 6aba6e6 commit 0b4a965

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,16 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo
128128
on a per repository basis by creating a file named ``.bash-git-rc`` with the
129129
content ``FETCH_REMOTE_STATUS=0`` in the root of your git repository.
130130

131-
- You can get help on the git prompt with the function ``git_prompt_help``.
132-
Examples are available with ``git_prompt_examples``.
131+
- You can get help on the git prompt with the function ``git_prompt_help``.
132+
Examples are available with ``git_prompt_examples``.
133+
134+
- If you make any changes to any file that is sourced by `gitprompt.sh`, you
135+
should run this command, so that the next prompt update will find all the
136+
files and source them anew.
137+
138+
```sh
139+
git_prompt_reset
140+
```
133141

134142
**Enjoy!**
135143

git-prompt-colors.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ define_git_prompt_colors() {
4242
if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then
4343
define_git_prompt_colors
4444
fi
45-

gitprompt.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ function gp_maybe_set_envar_to_path(){
6767
return 1
6868
}
6969

70+
# git_prompt_reset
71+
#
72+
# unsets selected GIT_PROMPT variables, causing the next prompt callback to
73+
# recalculate them from scratch.
74+
75+
git_prompt_reset() {
76+
local var
77+
for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD ; do
78+
unset $var
79+
done
80+
}
81+
7082
function git_prompt_config()
7183
{
7284
#Checking if root to change output
@@ -78,8 +90,8 @@ function git_prompt_config()
7890
# prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt
7991
# git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh
8092

81-
if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then
82-
source "$__PROMPT_COLORS_SH" # outsource the color defs
93+
if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then
94+
source "$__PROMPT_COLORS_FILE" # outsource the color defs
8395
else
8496
echo 1>&2 "Cannot find prompt-colors.sh!"
8597
fi
@@ -93,14 +105,15 @@ function git_prompt_config()
93105
echo 1>&2 "Cannot find git-prompt-colors.sh!"
94106
fi
95107

96-
if [ "x$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" == "x1" ]; then
108+
if [ "$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" = 1 ]; then
97109
if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then
98110
LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK";
99111
else
100112
LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL";
101113
fi
102114

103-
LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/$GIT_PROMPT_LAST_COMMAND_STATE}"
115+
# replace _LAST_COMMAND_STATE_ token with the actual state
116+
LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}"
104117
fi
105118

106119
# Do this only once to define PROMPT_START and PROMPT_END
@@ -219,8 +232,6 @@ function updatePrompt() {
219232
local PROMPT_START
220233
local PROMPT_END
221234
local EMPTY_PROMPT
222-
local GIT_PROMPT_FETCH_TIMEOUT
223-
local __GIT_STATUS_CMD
224235
local Blue="\[\033[0;34m\]"
225236

226237
git_prompt_config

0 commit comments

Comments
 (0)