From 839de0333fb6d8ae80ea6197872872da74b30782 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 19:44:46 +0200 Subject: [PATCH 1/3] Readied overwritten function for displaying the last command indicator --- gitprompt.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 1dab935..50863d0 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -93,6 +93,14 @@ function git_prompt_config() fi fi + if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then + if [ $LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; + else + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; + fi + fi + # Do this only once to define PROMPT_START and PROMPT_END if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then From 8a8e068e6682ef2720f01ff25d1fb6c8a2b1a96f Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 21:30:48 +0200 Subject: [PATCH 2/3] Removed declares in git-prompt-colors.sh as they are not compatible with the Bash on MacOS X --- git-prompt-colors.sh | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index aa76a49..7eff7c7 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,17 +1,5 @@ # These are the color definitions used by gitprompt.sh -declare -g GIT_PROMPT_PREFIX -declare -g GIT_PROMPT_SUFFIX -declare -g GIT_PROMPT_SEPARATOR -declare -g GIT_PROMPT_BRANCH -declare -g GIT_PROMPT_STAGED -declare -g GIT_PROMPT_CONFLICTS -declare -g GIT_PROMPT_CHANGED -declare -g GIT_PROMPT_REMOTE -declare -g GIT_PROMPT_UNTRACKED -declare -g GIT_PROMPT_STASHED -declare -g GIT_PROMPT_CLEAN - local Time12a="\$(date +%H:%M)" local PathShort="\w" From 957eb80d2a6f5a00d81b209256ec82ec63d2ff77 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 21:44:22 +0200 Subject: [PATCH 3/3] Readded the LAST_COMMAND_INDICATOR-Functionality, which got lost on last merge. Added fix for #67 --- README.md | 10 +++++++++- git-prompt-colors.sh | 6 ++++++ gitprompt.sh | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7f8131b..3fa86df 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,15 @@ function prompt_callback { - You can show an additional indicator at the start of the prompt, which shows the result of the last executed command by setting ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt - script + script. + If you want to display the exit code too, you can use the placeholder + ``_LAST_COMMAND_STATE_`` in ``GIT_PROMPT_COMMAND_OK`` or ``GIT_PROMPT_COMMAND_FAIL`` + in your ``.git-prompt-colors.sh``: + +```sh +GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # displays as ✔-0 +GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 for exit code 1 +``` - It is now possible to disable the fetching of the remote repository either globally by setting ``GIT_PROMPT_FETCH_REMOTE_STATUS=0`` in your .bashrc or diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 7eff7c7..4d2dd24 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -18,6 +18,12 @@ GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo +# For the command indicator, the placeholder _LAST_COMMAND_STATE_ +# will be replaced with the exit code of the last command +# e.g. +# GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 +# GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 diff --git a/gitprompt.sh b/gitprompt.sh index 50863d0..da136a6 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -62,7 +62,6 @@ function gp_maybe_set_envar_to_path(){ function git_prompt_config() { - #Checking if root to change output _isroot=false [[ $UID -eq 0 ]] && _isroot=true @@ -94,11 +93,13 @@ function git_prompt_config() fi if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then - if [ $LAST_COMMAND_STATE = 0 ]; then - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; - else - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; - fi + 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}}" fi # Do this only once to define PROMPT_START and PROMPT_END @@ -161,9 +162,11 @@ function git_prompt_config() fi } -function setGitPrompt() { - LAST_COMMAND_STATE=$? +function setLastCommandState() { + GIT_PROMPT_LAST_COMMAND_STATE=$? +} +function setGitPrompt() { local EMPTY_PROMPT local __GIT_STATUS_CMD @@ -181,11 +184,11 @@ function setGitPrompt() { fi if [[ -e "${repo}/.bash-git-rc" ]]; then - source "${repo}/.bash-git-rc" + source "${repo}/.bash-git-rc" fi if [ "x${FETCH_REMOTE_STATUS}" == "x1" ]; then - checkUpstream + checkUpstream fi updatePrompt @@ -294,7 +297,7 @@ function prompt_callback_default { return } -function run { +function gp_install_prompt { if [ "`type -t prompt_callback`" = 'function' ]; then prompt_callback="prompt_callback" else @@ -323,8 +326,21 @@ function run { esac fi + if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then + local setLastCommandStateEntry="setLastCommandState" + case ";$PROMPT_COMMAND;" in + *";$setLastCommandStateEntry;"*) + # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" + :;; + *) + PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" + # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" + ;; + esac + fi + git_prompt_dir source "$__GIT_PROMPT_DIR/git-prompt-help.sh" } -run +gp_install_prompt