Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ogr3 committed Jul 20, 2016
2 parents bbff98f + 38ae8dd commit a2ec3c8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo
git_prompt_reset
```

- You can disable/enable gitprompt by runnning:

```sh
git_prompt_toggle
```


**Enjoy!**

## Alternative RPM Install
Expand Down
32 changes: 31 additions & 1 deletion gitprompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function setGitPrompt() {

git_prompt_config

if [[ ! -e "$repo" ]]; then
if [[ ! -e "$repo" ]] || [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then
PS1="$EMPTY_PROMPT"
return
fi
Expand Down Expand Up @@ -437,6 +437,20 @@ function replaceSymbols() {
echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}}
}

function createPrivateIndex {
# Create a copy of the index to avoid conflicts with parallel git commands, e.g. git rebase.
local __GIT_INDEX_FILE
local __GIT_INDEX_PRIVATE
if [[ -z "$GIT_INDEX_FILE" ]]; then
__GIT_INDEX_FILE="$(git rev-parse --git-dir)/index"
else
__GIT_INDEX_FILE="$GIT_INDEX_FILE"
fi
__GIT_INDEX_PRIVATE="/tmp/git-index-private$$"
cp "$__GIT_INDEX_FILE" "$__GIT_INDEX_PRIVATE" 2>/dev/null
echo "$__GIT_INDEX_PRIVATE"
}

function updatePrompt() {
local LAST_COMMAND_INDICATOR
local PROMPT_LEADING_SPACE
Expand All @@ -456,6 +470,11 @@ function updatePrompt() {
export __GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES}
fi

local GIT_INDEX_PRIVATE="$(createPrivateIndex)"
#important to define GIT_INDEX_FILE as local: This way it only affects this function (and below) - even with the export afterwards
local GIT_INDEX_FILE
export GIT_INDEX_FILE="$GIT_INDEX_PRIVATE"

local -a git_status_fields
git_status_fields=($("$__GIT_STATUS_CMD" 2>/dev/null))

Expand Down Expand Up @@ -528,6 +547,7 @@ function updatePrompt() {
fi

PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}${ResetColor}}"
rm "$GIT_INDEX_PRIVATE" 2>/dev/null
}

# Helper function that returns virtual env information to be set in prompt
Expand Down Expand Up @@ -570,6 +590,16 @@ function prompt_callback_default {
return
}

# toggle gitprompt
function git_prompt_toggle() {
if [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then
GIT_PROMPT_DISABLE=0
else
GIT_PROMPT_DISABLE=1
fi
return
}

function gp_install_prompt {
if [ -z "$OLD_GITPROMPT" ]; then
OLD_GITPROMPT=$PS1
Expand Down
29 changes: 20 additions & 9 deletions gitstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@ num_conflicts=0
num_untracked=0
while IFS='' read -r line || [[ -n "$line" ]]; do
status=${line:0:2}
case "$status" in
\#\#) branch_line="${line/\.\.\./^}" ;;
?M) ((num_changed++)) ;;&
?D) ((num_changed++)) ;;&
U?) ((num_conflicts++)) ;;&
\?\?) ((num_untracked++)) ;;
\ ?) ;;
*) ((num_staged++)) ;;
esac
while [[ -n $status ]]; do
case "$status" in
#two fixed character matches, loop finished
\#\#) branch_line="${line/\.\.\./^}"; break ;;
\?\?) ((num_untracked++)); break ;;
U?) ((num_conflicts++)); break;;
?U) ((num_conflicts++)); break;;
DD) ((num_conflicts++)); break;;
AA) ((num_conflicts++)); break;;
#two character matches, first loop
?M) ((num_changed++)) ;;
?D) ((num_changed++)) ;;
?\ ) ;;
#single character matches, second loop
U) ((num_conflicts++)) ;;
\ ) ;;
*) ((num_staged++)) ;;
esac
status=${status:0:-1}
done
done <<< "$gitstatus"

num_stashed=0
Expand Down

0 comments on commit a2ec3c8

Please sign in to comment.