diff --git a/roles/bash/files/profile b/roles/bash/files/profile index e972eab..889a3d3 100644 --- a/roles/bash/files/profile +++ b/roles/bash/files/profile @@ -239,23 +239,15 @@ alias dark='_update_colors dark' # 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 - printf "\ePtmux;\e\e]" - else - 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\x5c" # 0x5c == backslash - else - printf "\a" - fi -} +if [ -n "$TMUX" ]; then + _OSC=$(printf "\ePtmux;\e\e]") + _ST=$(printf "\a\e\\") +else + _OSC=$(printf "\e]") + _ST=$(printf "\a") +fi _update_colors() { export BACKGROUND="$1" @@ -294,9 +286,7 @@ _set_iterm2_colors() { # 1: foreground, 2: background, 3: cursor local fg="$1" bg="$2" cursor="$3" local key rgb while read -r key rgb; do - _osc_start - printf "1337;SetColors=%s=%s" "$key" "${rgb}" - _osc_end + printf "%s1337;SetColors=%s=%s%s" "$_OSC" "$key" "${rgb}" "$_ST" 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 + printf "%s4;%s;rgb:%s/%s/%s%s" "$_OSC" "$c" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" "$_ST" 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 + printf "%s%s;rgb:%s/%s/%s%s" "$_OSC" "$Ps" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" "$_ST" done <