This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/common/colors/shell

89 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
if [ "${TERM%%-*}" = 'linux' ]; then
return 2>/dev/null || exit 0
fi
black="11/11/11"
red="f9/26/72"
green="a6/e2/2e"
yellow="f4/bf/75"
blue="66/d9/ef"
magenta="ae/81/ff"
cyan="a1/ef/e4"
white="cccccc"
if [ -n "$TMUX" ]; then
# tell tmux to pass the escape sequences through
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
printf_template="\033Ptmux;\033\033]4;%d;rgb:%s\007\033\\"
printf_template_var="\033Ptmux;\033\033]%d;rgb:%s\007\033\\"
printf_template_custom="\033Ptmux;\033\033]%s%s\007\033\\"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf_template="\033P\033]4;%d;rgb:%s\007\033\\"
printf_template_var="\033P\033]%d;rgb:%s\007\033\\"
printf_template_custom="\033P\033]%s%s\007\033\\"
elif [[ $- != *i* ]]; then
# non-interactive
alias printf=/bin/false
else
printf_template="\033]4;%d;rgb:%s\033\\"
printf_template_var="\033]%d;rgb:%s\033\\"
printf_template_custom="\033]%s%s\033\\"
fi
c() {
t="${1}"; shift
c="${1}"; shift
for n in "$@"; do
printf "$t" "$n" "$c"
done
}
ct() { c "$printf_template" "$@"; }
cv() { c "$printf_template" "$@"; }
cc() { c "$printf_template" "$@"; }
ct $black 0
ct $red 1 9
ct $green 2 10
ct $yellow 3 11
ct $blue 4 12
ct $magenta 5 13
ct $cyan 6 14
ct $white 7 10
if [ -n "$ITERM_SESSION_ID" ]; then
# iTerm2 proprietary escape codes
printf $printf_template_custom Pg f8f8f2 # forground
printf $printf_template_custom Ph 111111 # background
printf $printf_template_custom Pi f8f8f2 # bold color
printf $printf_template_custom Pj 49483e # selection color
printf $printf_template_custom Pk f8f8f2 # selected text color
printf $printf_template_custom Pl f8f8f2 # cursor
printf $printf_template_custom Pm 111111 # cursor text
else
cv $white 10
cv $black 11
cc ";7" 12
fi
unset -f c
unset -f ct
unset -f cv
unset -f cc
unset black
unset red
unset green
unset yellow
unset blue
unset magenta
unset cyan
unset white
unset printf_template
unset printf_template_var
unset printf_template_custom