mirror of
https://github.com/notwa/rc
synced 2025-02-05 15:43:22 -08:00
overengineer zsh and bash prompts
This commit is contained in:
parent
4e2002d0dd
commit
31afd5e358
2 changed files with 41 additions and 13 deletions
42
home/bashrc
42
home/bashrc
|
@ -15,19 +15,45 @@ set +o histexpand # disable expansion of ! characters
|
||||||
|
|
||||||
_temporary_scope_() {
|
_temporary_scope_() {
|
||||||
local t="${TERM%%-*}" title=
|
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
|
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
|
fi
|
||||||
|
|
||||||
local color_okay='\\[\e[42m\\]'
|
local G0="(" # change G0 charset
|
||||||
local color_fail='\\[\e[41m\\]'
|
local G1=")" # change G1 charset
|
||||||
local line1=' \\[\e[0m\\]'
|
local USASCII="B" # sane default
|
||||||
local line2='\\[\e[1;37m\\]\\$\\[\e[0m\\] '
|
local SPECIAL="0" # DEC Special Character and Line Drawing Set
|
||||||
local ret_okay="$title$color_okay$line1\n$color_okay$line2"
|
|
||||||
local ret_fail="$title$color_fail$line1\n$color_fail$line2"
|
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'"
|
PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'"
|
||||||
}; _temporary_scope_; unset _temporary_scope_
|
}; _temporary_scope_; unset -f _temporary_scope_
|
||||||
|
|
||||||
. ~/.shrc
|
. ~/.shrc
|
||||||
|
|
||||||
|
|
12
home/zshrc
12
home/zshrc
|
@ -234,9 +234,12 @@ function {
|
||||||
# zsh adds a % symbol to newline-less output, so my bash prompt is overkill
|
# 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
|
# NOTE: i've started hardcoding escapes instead of relying on zsh
|
||||||
# because detecting terminal features is too troublesome.
|
# because detecting terminal features is too troublesome.
|
||||||
local s=$'\x1B\x5B' # start escape code
|
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
|
||||||
local e=m # end escape code
|
local chset=$'\033\050B\017' # set G0 to USASCII charset and "shift-in" to it
|
||||||
local reset="${s}0${e}"
|
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 good=42 # green
|
||||||
local bad=41 # red
|
local bad=41 # red
|
||||||
|
|
||||||
|
@ -247,8 +250,7 @@ function {
|
||||||
(sabotage) good=45;; # magenta
|
(sabotage) good=45;; # magenta
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# NOTE: i had ${s}10${e} here before, is it still necessary?
|
PROMPT="%{$chset$curse$reset$s%(?.$good.$bad);97$e%}%#%{$reset%} "
|
||||||
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} "
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reload() { ### @-
|
reload() { ### @-
|
||||||
|
|
Loading…
Add table
Reference in a new issue