-
Notifications
You must be signed in to change notification settings - Fork 2
/
it2setcolor
executable file
·116 lines (106 loc) · 2.75 KB
/
it2setcolor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
open=0
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
# only accepts ESC backslash for ST.
function print_osc() {
if [[ $TERM == screen* ]] ; then
printf "\033Ptmux;\033\033]"
else
printf "\033]"
fi
}
# More of the tmux workaround described above.
function print_st() {
if [[ $TERM == screen* ]] ; then
printf "\a\033\\"
else
printf "\a"
fi
}
# set_color key rgb
function set_color() {
print_osc
printf '1337;SetColors=%s=%s' "$1" "$2"
print_st
}
function error() {
echo "ERROR: $*" 1>&2
}
function show_help() {
if [ $open = 1 ]; then
print_st
fi
echo "Usage"
echo ""
echo "1) To set a specific color to an RGB value:"
echo " it2setcolor name color [name color...]" 1>& 2
echo "For example:"
echo " it2setcolor fg fff"
echo ""
echo "name is one of:"
echo " fg bg bold link selbg selfg curbg curfg underline tab"
echo " black red green yellow blue magenta cyan white"
echo " br_black br_red br_green br_yellow br_blue br_magenta br_cyan br_white"
echo ""
echo "color is of the format:"
echo " RGB (three hex digits, like fff)"
echo " RRGGBB (six hex digits, like f0f0f0)"
echo " cs:RGB (cs is a color space name)"
echo " cs:RRGGBB (cs is a color space name)"
echo ""
echo " The color space names accepted in the color are:"
echo " srgb (sRGB, the default if none is specified)"
echo " rgb (Apple's old device-independent colorspace)"
echo " p3 (Apple's fancy large-gamut colorspace)"
echo ""
echo "2) To switch to a named color preset:"
echo " it2setcolor preset name"
echo "For example:"
echo " it2setcolor preset 'Light Background'"
echo ""
echo "3) To reset the current tab's color to the system default:"
echo " it2setcolor tab default"
}
# Show help if no arguments and no stdin.
if [ $# -eq 0 ]; then
show_help
exit
fi
# Look for command line flags.
while [ $# -gt 0 ]; do
case "$1" in
-h|--h|--help)
show_help
exit
;;
-*)
error "Unknown option flag: $1"
show_help
exit 1
;;
*)
if [ $# -lt 2 ]; then
show_help
exit
fi
if [ $open = 0 ]; then
open=1
print_osc
printf '1337;SetColors='
else
printf ","
fi
# name is not checked for validity because we'd like this to work with future colors, too.
printf "%s=%s" "$1" "$2"
shift
;;
esac
shift
done
if [ $open = 1 ]; then
print_st
else
show_help
fi
exit 0