Ditched the config variable GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR in favor of a more general approach with a placeholder.

Fixes #76
master
Martin Gondermann 11 years ago
parent 15a92a49af
commit 3569c97ba0
  1. 22
      README.md
  2. 9
      git-prompt-colors.sh
  3. 11
      gitprompt.sh

@ -18,6 +18,11 @@ if you have one. It now contains a function named ``define_git_prompt_colors()``
**Please see the updated ``git-prompt-colors.sh`` in the installation directory!** **Please see the updated ``git-prompt-colors.sh`` in the installation directory!**
---
**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder
named ``_LAST_COMMAND_INDICATOR_``, which is replaced by the state of the last executed command. It is now activated by default.**
## Examples ## Examples
The prompt may look like the following: The prompt may look like the following:
@ -92,9 +97,6 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
# Set config variables first # Set config variables first
GIT_PROMPT_ONLY_IN_REPO=1 GIT_PROMPT_ONLY_IN_REPO=1
# GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1 # uncomment if you want to show
# the exit code of the last command
# in your prompt
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# GIT_PROMPT_START=... # uncomment for custom prompt start sequence # GIT_PROMPT_START=... # uncomment for custom prompt start sequence
@ -140,10 +142,16 @@ function prompt_callback {
- If you want to show the git prompt only if you are in a git repository you - 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 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 - There is an indicator at the start of the prompt, which shows
the result of the last executed command by setting the result of the last executed command by if you put the placeholder
``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt `_LAST_COMMAND_INDICATOR_` in any of the prompt templates.
script. It is now by default activated in the default `git-prompt-colors.sh`:
```sh
GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"
```
If you want to display the exit code too, you can use the placeholder 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`` ``_LAST_COMMAND_STATE_`` in ``GIT_PROMPT_COMMAND_OK`` or ``GIT_PROMPT_COMMAND_FAIL``
in your ``.git-prompt-colors.sh``: in your ``.git-prompt-colors.sh``:

@ -25,16 +25,17 @@ define_git_prompt_colors() {
# GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 # 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_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_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_COMMAND_FAIL="${Red}" # indicator if the last command returned with an exit code of other than 0
# template for displaying the current virtual environment # template for displaying the current virtual environment
# use the placeholder _VIRTUALENV_ will be replaced with # use the placeholder _VIRTUALENV_ will be replaced with
# the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV)
GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "
GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL
GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"
GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "
GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "

@ -105,7 +105,6 @@ function git_prompt_config()
echo 1>&2 "Cannot find git-prompt-colors.sh!" echo 1>&2 "Cannot find git-prompt-colors.sh!"
fi fi
if [ "$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" = 1 ]; then
if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then
LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK";
else else
@ -114,7 +113,6 @@ function git_prompt_config()
# replace _LAST_COMMAND_STATE_ token with the actual state # replace _LAST_COMMAND_STATE_ token with the actual state
LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_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 # Do this only once to define PROMPT_START and PROMPT_END
@ -157,7 +155,7 @@ function git_prompt_config()
if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then
EMPTY_PROMPT="$OLD_GITPROMPT" EMPTY_PROMPT="$OLD_GITPROMPT"
else else
local ps="$LAST_COMMAND_INDICATOR" local ps=""
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$VIRTUAL_ENV" ]]; then
VENV=$(basename "${VIRTUAL_ENV}") VENV=$(basename "${VIRTUAL_ENV}")
ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}"
@ -166,7 +164,8 @@ function git_prompt_config()
VENV=$(basename "${CONDA_DEFAULT_ENV}") VENV=$(basename "${CONDA_DEFAULT_ENV}")
ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}"
fi fi
EMPTY_PROMPT="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" ps="$ps$PROMPT_START$($prompt_callback)$PROMPT_END"
EMPTY_PROMPT="${ps/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}"
fi fi
# fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes
@ -296,7 +295,7 @@ function updatePrompt() {
__chk_gitvar_status 'CLEAN' '-eq 1' - __chk_gitvar_status 'CLEAN' '-eq 1' -
__add_status "$ResetColor$GIT_PROMPT_SUFFIX" __add_status "$ResetColor$GIT_PROMPT_SUFFIX"
NEW_PROMPT="$LAST_COMMAND_INDICATOR" NEW_PROMPT=""
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$VIRTUAL_ENV" ]]; then
VENV=$(basename "${VIRTUAL_ENV}") VENV=$(basename "${VIRTUAL_ENV}")
NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}"
@ -312,7 +311,7 @@ function updatePrompt() {
NEW_PROMPT="$EMPTY_PROMPT" NEW_PROMPT="$EMPTY_PROMPT"
fi fi
PS1="$NEW_PROMPT" PS1="${NEW_PROMPT/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}"
} }
function prompt_callback_default { function prompt_callback_default {

Loading…
Cancel
Save