diff --git a/roles/bash/files/profile b/roles/bash/files/profile index ebd59d6..6dc28a6 100644 --- a/roles/bash/files/profile +++ b/roles/bash/files/profile @@ -220,90 +220,38 @@ alias dark='_update_colors dark' # * https://vt100.net/ # * https://iterm2.com/utilities/imgcat -_send_osc() { - local OSC ST +# In tmux, OSC sequences can be forwarded to the underlying terminal by: +# * Wrapping the sequence with `DCS tmux; ST` +# * Replacing ESC in with ESC ESC. +_osc_start() { if [ -n "$TMUX" ]; then - OSC=$'\ePtmux;\e\e]' - ST=$'\e\e\\\e\\'; + printf "\ePtmux;\e\e]" else - OSC=$'\e]' - ST=$'\e\\' + printf "\e]" + fi +} + +# Either ST or BEL (\a) can be used to end an OSC sequence. However, tmux +# requires ST to end its wrapping DCS. +_osc_end() { + if [ -n "$TMUX" ]; then + printf "\a\e\\" + else + printf "\a" fi - echo -n "$OSC$1$ST" } _update_colors() { - local cursor fg bg n rgb - export BACKGROUND="$1" if [ "$BACKGROUND" = "light" ]; then + _set_terminal_colors $Base01_RGB $Base3_RGB $Red_RGB # fg bg cursor PS1_SEP_COLOR=$(tput setaf $Base1) else + _set_terminal_colors $Base1_RGB $Base03_RGB $Red_RGB # fg bg cursor PS1_SEP_COLOR=$(tput setaf $Base01) fi - cursor=$Red_RGB - if [ "$BACKGROUND" = "light" ]; then - fg=$Base01_RGB - bg=$Base3_RGB - else - fg=$Base1_RGB - bg=$Base03_RGB - fi - - if [ -n "$ITERM_SESSION_ID" ]; then # iTerm2 - while read -r n rgb; do _send_osc "P$n$rgb"; done < 4;c;spec + # c -> index of the ANSI color to change [0..15] + # spec -> RGB value of color as rgb:RR/GG/BB + _osc_start + printf "4;%s;rgb:%s/%s/%s" "$c" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" + _osc_end + done < foreground (10), background (11), or cursor (12) + # Pt -> RGB value of color as rgb:RR/GG/BB + _osc_start + printf "%s;rgb:%s/%s/%s" "$Ps" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" + _osc_end + done <