dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit e65afaee820fbc44493eb3355e19d81b809d2dac
parent d29f07455bde59201ca7d427b5e753cabfa6baeb
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 11 Apr 2021 01:18:35 +0100

.c/k/kshrc .c/k/prompt: properly isolate prompt

Diffstat:
M.config/ksh/kshrc | 35-----------------------------------
M.config/ksh/prompt | 25+++++++++++++++----------
2 files changed, 15 insertions(+), 45 deletions(-)

diff --git a/.config/ksh/kshrc b/.config/ksh/kshrc @@ -18,41 +18,6 @@ settitle(){ printf "\033]0;%s\007" "$@" } -__ksh_prompt(){ - echo "$0" | grep -v ksh >/dev/null && { - printf "($(basename $0)) " - } - errorcode=$1 - tput setaf 10 - [ $errorcode -eq 0 ] && tput setaf 15 || tput setaf 10 - printf "%s " $errorcode - tput setaf 5 - printf "%s " $(whoami) - tput setaf 3 - printf "%s" $(git branch 2>/dev/null | grep '^*' | awk '{print $2 "|"}') - git diff 1>/dev/null 2>/dev/null && { - 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 --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-~-") - tput setaf 7 - printf "$ " - tput sgr0 -} - PS1="\$(__ksh_prompt \$?)\$(settitle ksh)" PS2="$(tput setaf 7):; $(tput sgr0)" PS3="$(tput setaf 7):; $(tput sgr0)$(tput el) " diff --git a/.config/ksh/prompt b/.config/ksh/prompt @@ -1,6 +1,9 @@ #!/bin/ksh -_ksh_prompt(){ +__ksh_prompt(){ + echo "$0" | grep -v ksh >/dev/null && { + printf "($(basename $0)) " + } errorcode=$1 tput setaf 10 [ $errorcode -eq 0 ] && tput setaf 15 || tput setaf 10 @@ -13,15 +16,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-~-")