commit 3038650ca50c02863683ab90e1dd46ac6ae8457b
parent c9bda683cd996f6d8fb8f3fddeb37cd414498606
Author: hhvn <hayden@haydenvh.com>
Date: Sat, 30 Jan 2021 15:00:24 +0000
.config/ksh/kshrc: fix git info retrieval
Diffstat:
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/.config/ksh/kshrc b/.config/ksh/kshrc
@@ -18,7 +18,7 @@ settitle(){
printf "\033]0;%s\007" "$1"
}
-_ksh_prompt(){
+ksh_prompt(){
errorcode=$1
tput setaf 10
[ $errorcode -eq 0 ] && tput setaf 15 || tput setaf 10
@@ -31,15 +31,17 @@ _ksh_prompt(){
git diff | grep '.' >/dev/null && tput setaf 8 || tput setaf 15
printf "%s+" $(git diff 2>/dev/null | grep -E '^(\+\+\+|---)' | sed -E 's~^[^a]*a/|^[^b]*b/~~' \
| grep -v /dev/null | uniq | wc -l | tr -d '\n' | grep '.' || printf 0)
- git log | head -n 1 | grep -v '(.*\/.*)' >/dev/null && tput setaf 14
- git log --pretty=format:"commit %h%d" | awk -v "c=0" '
- /^commit/ {
- if ($3 ~ /(.*\/.*)/) {
- printf("%d", c)
- exit
- } else c += 1
- }'
- printf '^ '
+ git log --pretty=format:"commit %h%d" | head -n 1 | grep -v '.*\/.*' >/dev/null && tput setaf 14 && {
+ git log --pretty=format:"commit %h%d" | awk -v "c=0" '
+ /^commit/ {
+ if ($0 ~ /\//) {
+ printf("%d", c)
+ exit
+ } else c += 1
+ }'
+ printf '^'
+ }
+ printf ' '
}
tput setaf 7
printf "%s " $(pwd | sed "s-$HOME-~-")
@@ -47,7 +49,8 @@ _ksh_prompt(){
printf "$ "
tput sgr0
}
-PS1="\$(_ksh_prompt \$?)"
+
+PS1="\$(ksh_prompt \$?)"
PS2="$(tput setaf 7):; $(tput sgr0)"
PS3="$(tput setaf 7):; $(tput sgr0)$(tput el) "
PS4="$(tput setaf 7):; $(tput sgr0)"