From d22e1b495e0f20edde45bda28ccb11087c7e7ce8 Mon Sep 17 00:00:00 2001 From: Martin Goldhahn Date: Wed, 17 Jul 2013 00:26:57 +0200 Subject: [PATCH 1/3] keep old prompt on non-git repository folders --- gitprompt.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index a49f784..31c1bc6 100644 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -49,7 +49,9 @@ GIT_PROMPT_CLEAN="${BGreen}✔" PROMPT_START="$Yellow$PathShort$ResetColor" PROMPT_END=" \n$WHITE$Time12a$ResetColor $ " - +if [ -z "$OLDPROMPT" ] ; then + export OLDPROMPT=$PS1 +fi function update_current_git_vars() { unset __CURRENT_GIT_STATUS @@ -101,7 +103,8 @@ function setGitPrompt() { PS1="$PYTHON_VIRTUALENV$PROMPT_START$STATUS$PROMPT_END" else - PS1="$PROMPT_START$PROMPT_END" + #PS1="$PROMPT_START$PROMPT_END" + PS1=$OLDPROMPT fi } From 238ab58560febdcf662f099ba81f2a51aa6a0a44 Mon Sep 17 00:00:00 2001 From: Martin Goldhahn Date: Sun, 4 Aug 2013 17:50:07 +0200 Subject: [PATCH 2/3] move configuration of git_prompt_dir inside a function --- gitprompt.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 7a1ed16..f9e5c69 100644 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -1,16 +1,19 @@ #!/bin/sh -# assume the gitstatus.py is in the same directory as this script -# code thanks to http://stackoverflow.com/questions/59895 -if [ -z "${__GIT_PROMPT_DIR}" ]; then - SOURCE="${BASH_SOURCE[0]}" - while [ -h "${SOURCE}" ]; do - DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" - SOURCE="$(readlink "${SOURCE}")" - [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" - done - __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" +function git_prompt_dir() +{ + # assume the gitstatus.py is in the same directory as this script + # code thanks to http://stackoverflow.com/questions/59895 + if [ -z "${__GIT_PROMPT_DIR}" ]; then + local SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + local DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + done + __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi +} function git_prompt_config() { @@ -31,7 +34,7 @@ function git_prompt_config() local Yellow="\[\033[0;33m\]" local White='\[\033[37m\]' local Red="\[\033[0;31m\]" - Blue="\[\033[0;34m\]" + local Blue="\[\033[0;34m\]" # Default values for the appearance of the prompt. Configure at will. GIT_PROMPT_PREFIX="[" @@ -69,7 +72,8 @@ function git_prompt_config() GIT_PROMPT_FETCH_TIMEOUT=${1-5} if [ "x$__GIT_STATUS_CMD" == "x" ] then - __GIT_STATUS_CMD="${__GIT_PROMPT_DIR:-${HOME}/.bash}/gitstatus.py" + git_prompt_dir + __GIT_STATUS_CMD="${__GIT_PROMPT_DIR}/gitstatus.py" fi } From ff7575ccdcc556e5ffb591bff85b8b7ac4e2f985 Mon Sep 17 00:00:00 2001 From: Martin Goldhahn Date: Sun, 4 Aug 2013 19:06:28 +0200 Subject: [PATCH 3/3] apply git prompt only on directories belonging to a git repository --- .gitignore | 2 ++ gitprompt.sh | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7683df --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.bak diff --git a/gitprompt.sh b/gitprompt.sh index f9e5c69..cb7254d 100644 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -98,6 +98,8 @@ function setGitPrompt() { local __GIT_STATUS_CMD git_prompt_config + + EMPTY_PROMPT=${OLD_GITPROMPT} local repo=`git rev-parse --show-toplevel 2> /dev/null` if [[ ! -e "${repo}" ]]; then @@ -167,6 +169,10 @@ function setGitPrompt() { fi } +if [ -z "$OLD_GITPROMPT" ]; then + OLD_GITPROMPT=$PS1 +fi + if [ -z "$PROMPT_COMMAND" ]; then PROMPT_COMMAND=setGitPrompt else