dot

packages and services management
Log | Files | Refs | README

commit f11ab5a9d2872932a28a70a0112e30441f0426bc
parent c9cafecf422ff68f39c7a143c9d09744fa0c56bc
Author: Josuah Demangeon⠠⠵ <mail@josuah.net>
Date:   Fri, 17 Mar 2017 14:50:25 +0100

Back to fancy prompt

Diffstat:
M.exrc | 2++
M.profile | 10++++++----
Dbin/git-pwd | 48------------------------------------------------
Abin/git-status | 45+++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/.exrc b/.exrc @@ -1 +1,3 @@ set number + +map g 1G diff --git a/.profile b/.profile @@ -33,14 +33,16 @@ export FILTER='iomenu' PS1='$( - [ "$?" -gt 0 ] && error="X" - git rev-parse 2>/dev/null && git="$(git status -s | wc -l)" + [ "$?" -gt 0 ] && error="1;31" || error="" + [ -z "${PWD##$HOME*}" ] && pwd="~${PWD#$HOME}" || pwd="$PWD" [ "$SSH_CONNECTION" ] && host="$(hostname)" printf "\033[?6c" - printf "\033]0;%s\007" "$(git-pwd)" # terminal name - printf "\n%s%1s• " "$host" "$git$error" + printf "\033]0;%s\007" "$pwd" + printf "\n" + printf "\033[1;30m%s\033[m %s\n" "$pwd" "$(git-status)" + printf "%s\033[%sm\$\033[m " "$host" "$error" )' PS2=': ' PS3=': ' diff --git a/bin/git-pwd b/bin/git-pwd @@ -1,48 +0,0 @@ -[ "${PWD##$HOME*}" ] && printf %s "$PWD" || printf ~%s "${PWD#$HOME}" - -git rev-parse 2> /dev/null && git status --porcelain -b | awk ' -/^## / { - branch = $0; - sub(/^## /, "", branch); - sub(/\.\.\..*/, "", branch); - - if ($0 ~ /ahead /) { - ahead = $0; - sub(/.*ahead /, "", ahead); - sub(/\].*|, .*/, "", ahead); - } - - if ($0 ~ /behind /) { - behind = $0; - sub(/.*behind /, "", behind); - sub(/\].*|, .*/, "", behind); - } - - next; -} - -/^\?\? / { untracked++; next; } -/^U. / { conflicts++; next; } -/^.U / { conflicts++; next; } -/^DD / { conflicts++; next; } -/^AA / { conflicts++; next; } -/^.M / { changed++; } -/^.D / { changed++; } -/^[^ ]. / { staged++; } - -END { - printf(" %s", branch); - - if (untracked + conflicts + changed + staged + behind + ahead == 0) { - printf " ok"; - } else { - if (untracked) printf " ?%d", untracked; - if (conflicts) printf " !%d", conflicts; - if (changed ) printf " +%d", changed; - if (staged ) printf " *%d", staged; - if (behind ) printf " ↓%d", behind; - if (ahead ) printf " ↑%d", ahead; - } -}' - -printf '\n' diff --git a/bin/git-status b/bin/git-status @@ -0,0 +1,45 @@ +git rev-parse 2> /dev/null && git status --porcelain -b | awk ' + +/^## / { + branch = $0; + sub(/^## /, "", branch); + sub(/\.\.\..*/, "", branch); + + if ($0 ~ /ahead /) { + ahead = $0; + sub(/.*ahead /, "", ahead); + sub(/\].*|, .*/, "", ahead); + } + + if ($0 ~ /behind /) { + behind = $0; + sub(/.*behind /, "", behind); + sub(/\].*|, .*/, "", behind); + } + + next; +} + +/^\?\? / { untracked++; next; } +/^U. / { conflicts++; next; } +/^.U / { conflicts++; next; } +/^DD / { conflicts++; next; } +/^AA / { conflicts++; next; } +/^.M / { changed++; } +/^.D / { changed++; } +/^[^ ]. / { staged++; } + +END { + printf("%s\033[m", branch); + + if (untracked + conflicts + changed + staged + behind + ahead == 0) { + printf " \033[1;32m✓\033[m"; + } else { + if (untracked) printf " \033[1;33m?\033[m%d", untracked; + if (conflicts) printf " \033[1;31m!\033[m%d", conflicts; + if (changed ) printf " \033[1;32m+\033[m%d", changed; + if (staged ) printf " \033[1;34m•\033[m%d", staged; + if (behind ) printf " \033[1;35m↓\033[m%d", behind; + if (ahead ) printf " \033[1;36m↑\033[m%d", ahead; + } +}'