all repos — dotfiles @ 670e041e0b48ee13a416021949f9550350776197

my *nix dotfiles

Better bash prompt

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Tue, 18 May 2021 10:13:41 +0530
commit

670e041e0b48ee13a416021949f9550350776197

parent

72b81d79bafbc42b137a5fbb093cfd56b9ffee2c

1 files changed, 11 insertions(+), 5 deletions(-)

jump to
M bash/.bashrc.d/99-prompt.bashbash/.bashrc.d/99-prompt.bash

@@ -15,13 +15,14 @@ local on_branch="On branch ([^${IFS}]*)"

local on_commit="HEAD detached at ([^${IFS}]*)" status="$(git status --porcelain 2> /dev/null)" local exit="$?" - color="" if [[ "$exit" -eq 0 ]]; then if [[ "${#status}" -eq 0 ]]; then - color="${grn}" + color="${grn}" + sym="·" else color="${red}" + sym="×" fi else printf ''

@@ -30,16 +31,21 @@

if [[ $git_status =~ $on_branch ]]; then local branch=${BASH_REMATCH[1]} - printf '%b' "$color $branch $rst" + printf '%b' " ($branch $color$sym$rst)" elif [[ $git_status =~ $on_commit ]]; then local commit=${BASH_REMATCH[1]} - printf '%b' "$color $commit $rst" + printf '%b' " ($commit $color$sym$rst)" fi } } +short_pwd() { + wd=$(dirs +0) + sed 's:\([^/]\)[^/]*/:\1/:g' <<< "${wd/#$HOME/\~}" +} + prompt_pwd() { - printf '%b' "\001${cyn}\002$(dirs +0)\001${rst}\002" + printf '%b' "\001${cyn}\002$(short_pwd)\001${rst}\002" } rootornot() {