From c68327a366a5535c1e07c09044e74db9fe45c1cf Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Mon, 22 Oct 2018 23:09:42 +0200 Subject: [PATCH] take back contributions from r13n --- bashrc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bashrc b/bashrc index 0e3d88b..79c14f5 100644 --- a/bashrc +++ b/bashrc @@ -1,13 +1,14 @@ # Get ourselves a nice prompt ks() { s="$?" ; $* ; return "$s" ; } -prompt_gbranch() { git branch | sed -n 's/^\* (*\(.* \)*\([^ )]*\))*$/\2/p' ; } -prompt_gbehind() { git status --branch --porcelain=2 | sed -n 's/^# branch\.ab.*-\([^0].*\)$/⇃\1/p' ; } -prompt_gbefore() { git status --branch --porcelain=2 | sed -n 's/^# branch\.ab +\([^0].*\) .*$/↿\1/p' ; } -prompt_gstatus() { git status --porcelain | sed 's/\(..\).*/\1/' | cat <(echo OK) - | tail -1 ; } prompt_git() { if git status 2>/dev/null 1>&2; then - echo " ($(prompt_gbranch)$(prompt_gbehind)$(prompt_gbefore)|$(prompt_gstatus))" + local branch="$(git branch | sed -n 's/^\* (*\(.* \)*\([^ )]*\))*$/\2/p')" + local behind="$(git status --branch --porcelain=2 | sed -n 's/^# branch\.ab.*-\([^0].*\)$/⇃\1/p')" + local before="$(git status --branch --porcelain=2 | sed -n 's/^# branch\.ab +\([^0].*\) .*$/↿\1/p')" + local status="$(git status --porcelain | sed 's/\(..\).*/\1/' | cat <(echo OK) - | tail -1)" + + echo " (${branch}${behind}${before}|${status})" fi } prompt_pwd() { @@ -15,14 +16,14 @@ prompt_pwd() { } prompt_status() { if [ "$?" = "0" ] - then echo " $" - else echo " %" + then echo "$" + else echo "%" fi } -BOLD="\[$(tput bold)\]" -GREEN="\[$(tput setaf 2)\]" -RESET="\[$(tput sgr0)\]" -PS1="$BOLD[\T]$RESET $GREEN\$(ks prompt_pwd)$RESET\$(ks prompt_git)\$(prompt_status) " +BOLD="\001$(tput bold)\002" +GREEN="\001$(tput setaf 2)\002" +RESET="\001$(tput sgr0)\002" +PS1="$BOLD[\T]$RESET $GREEN\$(ks prompt_pwd)$RESET\$(ks prompt_git) \$(prompt_status) " unset BOLD unset GREEN unset RESET