Added callback function to tweak prompt dynamicly

master
Danil Kutkevich 12 years ago
parent fc8e35f5a8
commit e1aeba7be6
  1. 24
      README.md
  2. 15
      gitprompt.sh

@ -43,11 +43,25 @@ The symbols are as follows:
## Install ## Install
1. Clone this repository to your homedir e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` 1. Clone this repository to your homedir
1. configure your prompt and source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt``
* you can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt 2. Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file
* If you want to tweak the colors, currently you have to tweak it in the ``gitprompt.sh`` 3. Go in a git repository and test it!
1. Go in a git repository and test it!
## Configuration
1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt
2. If you want to tweak the colors,
currently you have to tweak it in the ``gitprompt.sh``
3. You can define ``prompt_callback`` function to tweak your prompt dynamicly
```sh
function prompt_callback {
if [ `jobs | wc -l` -ne 0 ]; then
echo -n " jobs:\j"
fi
}
```
**Enjoy!** **Enjoy!**

@ -73,7 +73,7 @@ function git_prompt_config()
PROMPT_END="${GIT_PROMPT_END}" PROMPT_END="${GIT_PROMPT_END}"
fi fi
EMPTY_PROMPT="${PROMPT_START}${PROMPT_END}" EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}"
# fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes
GIT_PROMPT_FETCH_TIMEOUT=${1-5} GIT_PROMPT_FETCH_TIMEOUT=${1-5}
@ -182,7 +182,7 @@ function updatePrompt() {
STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}"
PS1="${PROMPT_START}${STATUS}${PROMPT_END}" PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}"
if [[ -n "${VIRTUAL_ENV}" ]]; then if [[ -n "${VIRTUAL_ENV}" ]]; then
PS1="${Blue}($(basename "${VIRTUAL_ENV}"))${ResetColor} ${PS1}" PS1="${Blue}($(basename "${VIRTUAL_ENV}"))${ResetColor} ${PS1}"
fi fi
@ -192,6 +192,16 @@ function updatePrompt() {
fi fi
} }
function prompt_callback_default {
return
}
if [ "`type -t prompt_callback`" = 'function' ]; then
prompt_callback="prompt_callback"
else
prompt_callback="prompt_callback_default"
fi
if [ -z "$OLD_GITPROMPT" ]; then if [ -z "$OLD_GITPROMPT" ]; then
OLD_GITPROMPT=$PS1 OLD_GITPROMPT=$PS1
fi fi
@ -203,4 +213,3 @@ else
PROMPT_COMMAND=${PROMPT_COMMAND%\;}; # remove trailing semi-colon PROMPT_COMMAND=${PROMPT_COMMAND%\;}; # remove trailing semi-colon
PROMPT_COMMAND="$PROMPT_COMMAND;setGitPrompt" PROMPT_COMMAND="$PROMPT_COMMAND;setGitPrompt"
fi fi

Loading…
Cancel
Save