Merge pull request #16 from maddingo/master

put git_prompt_dir in a function and apply gitprompt only to git repositories
master
Martin Gondermann 13 years ago
commit 6a80c55b3a
  1. 2
      .gitignore
  2. 34
      gitprompt.sh

2
.gitignore vendored

@ -0,0 +1,2 @@
*~
*.bak

@ -1,16 +1,19 @@
#!/bin/sh #!/bin/sh
# assume the gitstatus.py is in the same directory as this script function git_prompt_dir()
# code thanks to http://stackoverflow.com/questions/59895 {
if [ -z "${__GIT_PROMPT_DIR}" ]; then # assume the gitstatus.py is in the same directory as this script
SOURCE="${BASH_SOURCE[0]}" # code thanks to http://stackoverflow.com/questions/59895
while [ -h "${SOURCE}" ]; do if [ -z "${__GIT_PROMPT_DIR}" ]; then
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" local SOURCE="${BASH_SOURCE[0]}"
SOURCE="$(readlink "${SOURCE}")" while [ -h "${SOURCE}" ]; do
[[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" local DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
done SOURCE="$(readlink "${SOURCE}")"
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}"
done
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
fi fi
}
function git_prompt_config() function git_prompt_config()
{ {
@ -31,7 +34,7 @@ function git_prompt_config()
local Yellow="\[\033[0;33m\]" local Yellow="\[\033[0;33m\]"
local White='\[\033[37m\]' local White='\[\033[37m\]'
local Red="\[\033[0;31m\]" 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. # Default values for the appearance of the prompt. Configure at will.
GIT_PROMPT_PREFIX="[" GIT_PROMPT_PREFIX="["
@ -69,7 +72,8 @@ function git_prompt_config()
GIT_PROMPT_FETCH_TIMEOUT=${1-5} GIT_PROMPT_FETCH_TIMEOUT=${1-5}
if [ "x$__GIT_STATUS_CMD" == "x" ] if [ "x$__GIT_STATUS_CMD" == "x" ]
then then
__GIT_STATUS_CMD="${__GIT_PROMPT_DIR:-${HOME}/.bash}/gitstatus.py" git_prompt_dir
__GIT_STATUS_CMD="${__GIT_PROMPT_DIR}/gitstatus.py"
fi fi
} }
@ -94,6 +98,8 @@ function setGitPrompt() {
local __GIT_STATUS_CMD local __GIT_STATUS_CMD
git_prompt_config git_prompt_config
EMPTY_PROMPT=${OLD_GITPROMPT}
local repo=`git rev-parse --show-toplevel 2> /dev/null` local repo=`git rev-parse --show-toplevel 2> /dev/null`
if [[ ! -e "${repo}" ]]; then if [[ ! -e "${repo}" ]]; then
@ -163,6 +169,10 @@ function setGitPrompt() {
fi fi
} }
if [ -z "$OLD_GITPROMPT" ]; then
OLD_GITPROMPT=$PS1
fi
if [ -z "$PROMPT_COMMAND" ]; then if [ -z "$PROMPT_COMMAND" ]; then
PROMPT_COMMAND=setGitPrompt PROMPT_COMMAND=setGitPrompt
else else

Loading…
Cancel
Save