#!/bin/bash # Solarize the terminal # Useful terminal control sequences: # # Sequence Abbrev Description # ----- ----- ----------------------------- # ESC P DCS Device Control String # ESC [ CSI Control Sequence Introducer # ESC \ ST String Terminator # ESC ] OSC Operating System Control # # # More info at: # * https://www.xfree86.org/4.8.0/ctlseqs.html # * https://vt100.net/ # * https://iterm2.com/utilities/imgcat # 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. # Either ST or BEL (\a) can be used to end an OSC sequence. However, tmux # requires ST to end its wrapping DCS. if [ -n "$TMUX" ]; then _OSC=$(printf '\ePtmux;\e\e]') _ST=$(printf '\a\e\\') else _OSC=$(printf '\e]') _ST=$(printf '\a') fi # Color definitions (from http://ethanschoonover.com/solarized) Base03="002B36" Base02="073642" Base01="586E75" Base00="657B83" Base0="839496" Base1="93A1A1" Base2="EEE8D5" Base3="FDF6E3" Red="DC322F" Orange="CB4B16" Yellow="B58900" Green="859900" Cyan="2AA198" Blue="268BD2" Violet="6C71C4" Magenta="D33682" # Documentation for iTerm2 at # https://iterm2.com/documentation-escape-codes.html # under the heading "Change the color palette". set_iterm2_colors() { # 1: foreground, 2: background, 3: cursor while read -r key rgb; do 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 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 printf "%s%s;rgb:%s/%s/%s%s" "$_OSC" "$Ps" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" "$_ST" done </dev/null && [ -f "$ls_colors" ]; then eval "$(dircolors "$ls_colors")" fi } main