mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
squeeze lines for the bash prompt
This commit is contained in:
parent
31afd5e358
commit
a7e2eae559
1 changed files with 12 additions and 32 deletions
44
home/bashrc
44
home/bashrc
|
@ -15,43 +15,23 @@ set +o histexpand # disable expansion of ! characters
|
||||||
|
|
||||||
_temporary_scope_() {
|
_temporary_scope_() {
|
||||||
local t="${TERM%%-*}" title=
|
local t="${TERM%%-*}" title=
|
||||||
|
local hide='\\[' show='\\]' prompt='\\$' cwd='\\w' host='\\H'
|
||||||
local ESC="\\E"
|
local ESC='\E' BEL='\a' SI='\017' SO='\016' # SI/SO: switch to G0/G1 charset
|
||||||
local BEL="\\a"
|
local CSI="$ESC[" OSC="$ESC]"
|
||||||
local SI="\\017" # switch to G0 charset
|
local G0="(" G1=")" # change G0/G1 charset
|
||||||
local SO="\\016" # switch to G1 charset
|
local USASCII="B" SPECIAL="0" # charsets: sane default & line drawing
|
||||||
|
|
||||||
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 DECTCEM="25"
|
local DECTCEM="25"
|
||||||
local DECSET="h"
|
local DECSET="h" SGR="m" # final characters of a command sequence
|
||||||
local SGR="m"
|
|
||||||
|
|
||||||
local sanity="$ESC$G0$USASCII$SI$CSI?$DECTCEM$DECSET"
|
local sanity="$ESC$G0$USASCII$SI$CSI?$DECTCEM$DECSET"
|
||||||
local hide="\\\\["
|
local color1="$CSI;--$SGR" color2="$CSI--;97$SGR" reset="$hide$CSI$SGR$show"
|
||||||
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 line1="$hide$title$sanity$color1$show $reset"
|
||||||
local line2="$hide$color2$show$prompt$reset "
|
local line2="$hide$color2$show$prompt$reset "
|
||||||
local ret="$line1\\n$line2"
|
local ret="$line1\\n$line2"
|
||||||
local ret_okay="${ret//--/42}" # use green background
|
local ret_okay="${ret//--/42}" ret_fail="${ret//--/41}" # green/red bg
|
||||||
local ret_fail="${ret//--/41}" # use red background
|
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'"
|
PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'"
|
||||||
}; _temporary_scope_; unset -f _temporary_scope_
|
}; _temporary_scope_; unset -f _temporary_scope_
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue