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. 5
      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!**
---
**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
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
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_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
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.
- There is an indicator at the start of the prompt, which shows
the result of the last executed command by if you put the placeholder
`_LAST_COMMAND_INDICATOR_` in any of the prompt templates.
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
``_LAST_COMMAND_STATE_`` in ``GIT_PROMPT_COMMAND_OK`` or ``GIT_PROMPT_COMMAND_FAIL``
in your ``.git-prompt-colors.sh``:

@ -33,8 +33,9 @@ define_git_prompt_colors() {
# the name of the current virtual environment (currently CONDA and VIRTUAL_ENV)
GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "
GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"
# _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL
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_ROOT=" \n${White}${Time12a}${ResetColor} # "

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

Loading…
Cancel
Save