Implemented the possibility for an indicator which shows the result of the last command.

To enable just write

export GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1

just before sourcing the gitprompt.sh

fixes #60
master
Martin Gondermann 12 years ago
parent 0c2d76d226
commit 71001b1215
  1. 3
      README.md
  2. 3
      git-prompt-colors.sh
  3. 24
      gitprompt.sh

@ -93,6 +93,9 @@ function prompt_callback {
- If you want to show the git prompt only, if you are in a git repository you can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script
- 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
- You can get help on the git prompt with the function ``git_prompt_help``.
Examples are available with ``git_prompt_examples``.

@ -16,6 +16,9 @@ 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
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
GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "

@ -43,6 +43,7 @@ function git_prompt_config()
local Red="\[\033[0;31m\]"
local Blue="\[\033[0;34m\]"
local Cyan="\[\033[0;36m\]"
local Green="\[\033[0;32m\]"
#Checking if root to change output
_isroot=false
@ -88,6 +89,8 @@ function git_prompt_config()
GIT_PROMPT_UNTRACKED="${Cyan}"
GIT_PROMPT_STASHED="${BoldBlue}"
GIT_PROMPT_CLEAN="${BoldGreen}"
GIT_PROMPT_COMMAND_OK="${Green}"
GIT_PROMPT_COMMAND_FAIL="${Red}"
GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}"
@ -97,7 +100,15 @@ function git_prompt_config()
# Please do not add colors to these symbols
GIT_PROMPT_SYMBOLS_AHEAD="↑·"
GIT_PROMPT_SYMBOLS_BEHIND="↓·"
GIT_PROMPT_SYMBOLS_PREHASH=":"
GIT_PROMPT_SYMBOLS_PREHASH=":"
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
if [ "x${GIT_PROMPT_START}" == "x" ]; then
@ -133,11 +144,11 @@ function git_prompt_config()
EMPTY_PROMPT=$OLD_GITPROMPT
else
if [[ -n "${VIRTUAL_ENV}" ]]; then
EMPTY_PROMPT="(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}"
EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}"
elif [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
EMPTY_PROMPT="(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}"
EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}"
else
EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}"
EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${PROMPT_END}"
fi
fi
@ -159,6 +170,7 @@ function git_prompt_config()
}
function setGitPrompt() {
LAST_COMMAND_STATE=$?
local EMPTY_PROMPT
local __GIT_STATUS_CMD
@ -204,13 +216,13 @@ function updatePrompt() {
local GIT_PROMPT_UNTRACKED
local GIT_PROMPT_STASHED
local GIT_PROMPT_CLEAN
local LAST_COMMAND_INDICATOR
local PROMPT_LEADING_SPACE
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
@ -265,7 +277,7 @@ function updatePrompt() {
STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}"
PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}"
PS1="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}"
if [[ -n "${VIRTUAL_ENV}" ]]; then
PS1="(${Blue}$(basename ${VIRTUAL_ENV})${ResetColor}) ${PS1}"
fi

Loading…
Cancel
Save