1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-30 19:07:11 -07:00

overengineer zsh and bash prompts

This commit is contained in:
Connor Olding 2024-04-02 22:22:51 -07:00
parent 4e2002d0dd
commit 31afd5e358
2 changed files with 41 additions and 13 deletions

View File

@ -15,19 +15,45 @@ set +o histexpand # disable expansion of ! characters
_temporary_scope_() {
local t="${TERM%%-*}" title=
local ESC="\\E"
local BEL="\\a"
local SI="\\017" # switch to G0 charset
local SO="\\016" # switch to G1 charset
local CSI="$ESC["
local OSC="$ESC]"
if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then
title='\[\033]2;\w\a\]'
title="\\\\w"
[ "$t" = tmux ] || title="\\\\H: $title"
title="${OSC}2;$title$BEL"
fi
local color_okay='\\[\e[42m\\]'
local color_fail='\\[\e[41m\\]'
local line1=' \\[\e[0m\\]'
local line2='\\[\e[1;37m\\]\\$\\[\e[0m\\] '
local ret_okay="$title$color_okay$line1\n$color_okay$line2"
local ret_fail="$title$color_fail$line1\n$color_fail$line2"
local G0="(" # change G0 charset
local G1=")" # change G1 charset
local USASCII="B" # sane default
local SPECIAL="0" # DEC Special Character and Line Drawing Set
local DECTCEM="25"
local DECSET="h"
local SGR="m"
local sanity="$ESC$G0$USASCII$SI$CSI?$DECTCEM$DECSET"
local hide="\\\\["
local show="\\\\]"
local prompt="\\\\$"
local reset="$hide$CSI$SGR$show"
local color1="$CSI;--$SGR"
local color2="$CSI--;97$SGR"
local line1="$hide$title$sanity$color1$show $reset"
local line2="$hide$color2$show$prompt$reset "
local ret="$line1\\n$line2"
local ret_okay="${ret//--/42}" # use green background
local ret_fail="${ret//--/41}" # use red background
PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'"
}; _temporary_scope_; unset _temporary_scope_
}; _temporary_scope_; unset -f _temporary_scope_
. ~/.shrc

View File

@ -234,9 +234,12 @@ function {
# zsh adds a % symbol to newline-less output, so my bash prompt is overkill
# NOTE: i've started hardcoding escapes instead of relying on zsh
# because detecting terminal features is too troublesome.
local s=$'\x1B\x5B' # start escape code
local e=m # end escape code
local reset="${s}0${e}"
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
local chset=$'\033\050B\017' # set G0 to USASCII charset and "shift-in" to it
local s=$'\033\133' # CSI
local e=m # SGR
local reset=$s$e
local curse=$s$'?25h' # show cursor (DECTCEM)
local good=42 # green
local bad=41 # red
@ -247,8 +250,7 @@ function {
(sabotage) good=45;; # magenta
esac
# NOTE: i had ${s}10${e} here before, is it still necessary?
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} "
PROMPT="%{$chset$curse$reset$s%(?.$good.$bad);97$e%}%#%{$reset%} "
}
reload() { ### @-