diff options
-rw-r--r-- | bash-git-prompt | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/bash-git-prompt b/bash-git-prompt index 4a510ba..1397a50 100644 --- a/bash-git-prompt +++ b/bash-git-prompt @@ -1,21 +1,50 @@ #!/bin/bash -PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}<\t> \[\033[01;32m\]\u\[\033[00m\]@\[\033[01;33m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]' - set -o pipefail +[[ "$TERM" = *-color ]] && mitFarbe=true || mitFarbe=false + +[ -z "$PS1save" ] && PS1save="$PS1" + +if echo "$PS1save" | grep -q "\S" +then + PS1Ende="$(echo "$PS1save" | sed "s|^.*[^\\]\(\\\\\?\S\s*\)\$|\1|")" + PS1="$(echo "$PS1save" | sed "s|\\\\\?\S\s*\$||")" +else + PS1Ende="" + PS1="$PS1save" +fi + if branch=$(git branch 2>/dev/null | grep '\*' | cut -d' ' -f2) then - if git status --porcelain | grep -q "^.\S" + PS1="$PS1 " + git status --porcelain | grep -q "^.\S" && wtClean=false || wtClean=true + git status --porcelain | grep -q "^\S" && idxClean=false || idxClean=true + if $mitFarbe then - PS1="$PS1 \[\033[01;31m\]" - elif git status --porcelain | grep -q "^\S" + if ! $wtClean + then + PS1="$PS1\[\033[01;31m\]" + elif ! $idxClean + then + PS1="$PS1\[\033[01;33m\]" + else + PS1="$PS1\[\033[01;32m\]" + fi + fi + PS1="$PS1$branch" + if $mitFarbe then - PS1="$PS1 \[\033[01;33m\]" + PS1="$PS1\[\033[00m\]" else - PS1="$PS1 \[\033[01;32m\]" + if ! $wtClean + then + PS1="$PS1!" + elif ! $idxClean + then + PS1="$PS1+" + fi fi - PS1="$PS1$branch\[\033[00m\]\$ " -else - PS1="$PS1\$ " fi + +PS1="$PS1$PS1Ende" |