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/terminal_colors

89 lines
2.1 KiB
Text
Raw Permalink Normal View History

2017-02-07 16:16:45 -06:00
#!/bin/sh
if [ "${TERM%%-*}" = 'linux' ]; then
2021-07-04 11:01:15 -05:00
return 2>/dev/null || exit 0
2017-02-07 16:16:45 -06:00
fi
2021-07-04 11:01:15 -05:00
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"
2017-02-07 16:16:45 -06:00
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
2021-07-04 11:01:15 -05:00
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
2017-02-07 16:16:45 -06:00
if [ -n "$ITERM_SESSION_ID" ]; then
# iTerm2 proprietary escape codes
printf $printf_template_custom Pg f8f8f2 # forground
2018-09-25 14:19:35 -05:00
printf $printf_template_custom Ph 111111 # background
2017-02-07 16:16:45 -06:00
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
2018-09-25 14:19:35 -05:00
printf $printf_template_custom Pm 111111 # cursor text
2017-02-07 16:16:45 -06:00
else
2021-07-04 11:01:15 -05:00
cv $white 10
cv $black 11
cc ";7" 12
2017-02-07 16:16:45 -06:00
fi
2021-07-04 11:01:15 -05:00
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
2017-02-07 16:16:45 -06:00
unset printf_template
unset printf_template_var
2021-07-04 11:01:15 -05:00
unset printf_template_custom