From 7872f2cb67c6b4fe5d3ed841891b8371b13649b5 Mon Sep 17 00:00:00 2001 From: Alexander Blinne Date: Mon, 11 Apr 2016 22:09:51 +0200 Subject: sollte jetzt flexibel genug sein --- bash-git-prompt | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file 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" -- cgit v1.2.3-70-g09d2