Skip to content

Commit

Permalink
Merge pull request #72 from aks/master
Browse files Browse the repository at this point in the history
Added git_prompt_reset
  • Loading branch information
magicmonty committed Aug 29, 2014
2 parents 8826ec6 + 6aba6e6 commit 0b4a965
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,16 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo
on a per repository basis by creating a file named ``.bash-git-rc`` with the
content ``FETCH_REMOTE_STATUS=0`` in the root of your git repository.

- You can get help on the git prompt with the function ``git_prompt_help``.
Examples are available with ``git_prompt_examples``.
- You can get help on the git prompt with the function ``git_prompt_help``.
Examples are available with ``git_prompt_examples``.

- If you make any changes to any file that is sourced by `gitprompt.sh`, you
should run this command, so that the next prompt update will find all the
files and source them anew.

```sh
git_prompt_reset
```

**Enjoy!**

Expand Down
1 change: 0 additions & 1 deletion git-prompt-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ define_git_prompt_colors() {
if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then
define_git_prompt_colors
fi

23 changes: 17 additions & 6 deletions gitprompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ function gp_maybe_set_envar_to_path(){
return 1
}

# git_prompt_reset
#
# unsets selected GIT_PROMPT variables, causing the next prompt callback to
# recalculate them from scratch.

git_prompt_reset() {
local var
for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD ; do
unset $var
done
}

function git_prompt_config()
{
#Checking if root to change output
Expand All @@ -78,8 +90,8 @@ function git_prompt_config()
# prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt
# git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh

if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then
source "$__PROMPT_COLORS_SH" # outsource the color defs
if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then
source "$__PROMPT_COLORS_FILE" # outsource the color defs
else
echo 1>&2 "Cannot find prompt-colors.sh!"
fi
Expand All @@ -93,14 +105,15 @@ function git_prompt_config()
echo 1>&2 "Cannot find git-prompt-colors.sh!"
fi

if [ "x$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" == "x1" ]; then
if [ "$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" = 1 ]; then
if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then
LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK";
else
LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL";
fi

LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/$GIT_PROMPT_LAST_COMMAND_STATE}"
# replace _LAST_COMMAND_STATE_ token with the actual state
LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}"
fi

# Do this only once to define PROMPT_START and PROMPT_END
Expand Down Expand Up @@ -219,8 +232,6 @@ function updatePrompt() {
local PROMPT_START
local PROMPT_END
local EMPTY_PROMPT
local GIT_PROMPT_FETCH_TIMEOUT
local __GIT_STATUS_CMD
local Blue="\[\033[0;34m\]"

git_prompt_config
Expand Down

0 comments on commit 0b4a965

Please sign in to comment.