#!/bin/sh # 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 awk -v osc="$OSC" -v st="$ST" -v ORS="" \ '{print osc "4;" $1 ";rgb:" substr($2,1,2) "/" substr($2,3,2) "/" substr($2,5,2) st}' \ < foreground (10), background (11), or cursor (12) # Pt -> RGB value of color as rgb:RR/GG/BB awk -v osc="$OSC" -v st="$ST" -v ORS="" \ '{print osc $1 ";rgb:" substr($2,1,2) "/" substr($2,3,2) "/" substr($2,5,2) st}' \ </dev/null 2>&1 && [ -f "$ls_colors" ]; then eval "$(dircolors "$ls_colors")" fi } main