1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 04:39:03 -08:00

squeeze lines for the bash prompt

This commit is contained in:
Connor Olding 2024-04-03 17:40:07 -07:00
parent 31afd5e358
commit a7e2eae559

View file

@ -15,43 +15,23 @@ 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="\\\\w"
[ "$t" = tmux ] || title="\\\\H: $title"
title="${OSC}2;$title$BEL"
fi
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 hide='\\[' show='\\]' prompt='\\$' cwd='\\w' host='\\H'
local ESC='\E' BEL='\a' SI='\017' SO='\016' # SI/SO: switch to G0/G1 charset
local CSI="$ESC[" OSC="$ESC]"
local G0="(" G1=")" # change G0/G1 charset
local USASCII="B" SPECIAL="0" # charsets: sane default & line drawing
local DECTCEM="25"
local DECSET="h"
local SGR="m"
local DECSET="h" SGR="m" # final characters of a command sequence
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 color1="$CSI;--$SGR" color2="$CSI--;97$SGR" reset="$hide$CSI$SGR$show"
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
local ret_okay="${ret//--/42}" ret_fail="${ret//--/41}" # green/red bg
if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then
[ "$t" = tmux ] && title="$cwd" || title="$host: $cwd"
title="${OSC}2;$title$BEL"
fi
PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'"
}; _temporary_scope_; unset -f _temporary_scope_