-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitp.sh
executable file
·417 lines (390 loc) · 9.96 KB
/
itp.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/bin/bash
#started with info from
# source iterm2.zsh
# iTerm2 window/tab color commands
# Requires iTerm2 >= Build 1.0.0.20110804
# http://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes
#Written by Matt Pippitt to change iTerm2 look and feel from the command line
#variables
#annoying block to look where the script is, then set that directory to search for presets and colors
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
TARGET="$(readlink "$SOURCE")"
if [[ $TARGET == /* ]]; then
SOURCE="$TARGET"
else
DIR="$( dirname "$SOURCE" )"
SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
fi
done
RDIR="$( dirname "$SOURCE" )"
ITPDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#end annoying block
#Set variables, look in ~ first then $ITPDIR
#TODO maybe set something if neither exist to change the script behavior, like not show menu options
if [ -f ~/itp_presets ] ; then
PRESETSFILE=~/itp_presets
elif [ -f $ITPDIR/itp_presets ] ; then
PRESETSFILE=$ITPDIR/itp_presets
else
PRESETSFILE=notset
fi
if [ -f ~/itp_colors.list ] ; then
COLORSFILE=~/itp_colors.list
elif [ -f $ITPDIR/itp_colors.list ] ; then
COLORSFILE=$ITPDIR/itp_colors.list
else
COLORSFILE=notset
fi
showhelp() {
echo "Usage: $0 [OPTION(S)]"
echo "Options: "
echo " -b [badge text]"
echo " -P [preset name]"
echo " -p [profile name]"
echo " -t [colon separate RGB values] i.e 255:0:0 for red"
echo " -R yes Will reset profile and tab color to defaults "
}
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
echo -ne "\033]6;1;bg;blue;brightness;$3\a"
}
tab-color-picker() {
clear
echo -n "**** Tab Colors *****
0. From file list
1. Red
2. Orange
3. Yellow
4. Green
5. Blue
6. Indigo
7. Violet
8. White
9. Custom
x. Exit
Enter selection or x to quit: "
RETURN=$1
read answer
case $answer in
0)
#fancy nested list from file
tab-color-from-nested-file
;;
1)
#red
tab-color 255 0 0
;;
2)
#orange
tab-color 255 165 0
;;
3)
#yellow
tab-color 255 255 0
;;
4)
#green
tab-color 0 128 0
;;
5)
#blue
tab-color 0 0 255
;;
6)
#indigo
tab-color 75 0 130
;;
7)
#violet
tab-color 238 130 238
;;
8)
#white
tab-color 255 255 255
;;
9)
echo See http://en.wikipedia.org/wiki/Web_colors#X11_color_names
echo -n "Amount Red 0-255:"
read RED
echo -n "Amount Green 0-255:"
read GREEN
echo -n "Amount Blue 0-255:"
read BLUE
tab-color $RED $GREEN $BLUE
;;
x|q|X|Q)
exit
;;
*)
echo "easy tiger, exiting"
exit
;;
esac
}
tab-color-from-nested-file() {
if [ -s $COLORSFILE ] ; then
Number=0
clear
echo "**** Defined Color Groups *****"
declare -a CGARRAY=(`grep colors$ $COLORSFILE | awk '{print $1}'|tr '\n' ' '`);
for CG in `echo ${CGARRAY[@]}` ; do
echo $Number. $CG
Number=`expr $Number + 1`
done
LASTCHOICE=`expr $Number - 1`
echo -n "x. Exit
Enter selection or x to quit: "
read answer
echo 0-$LASTCHOICE
case $answer in
#for now there can only be 100 color groups
[0-9]|[0-9][0-9])
if [ "$answer" -gt "$LASTCHOICE" ] ; then
echo "Not a valid choice, should be between 0 and $LASTCHOICE"
read junk
fi
COLORGROUP=${CGARRAY[$answer]}
;;
x|q|X|Q)
exit
;;
*)
echo "Not a valid choice, should be between 0 and $LASTCHOICE, exiting"
exit
;;
esac
#now we have the group get the color list in that group
Number=0
clear
echo "**** Defined $COLORGROUP colors *****"
declare -a CGARRAY=(`sed -e '/./{H;$!d;}' -e 'x;/'${COLORGROUP}' colors/!d' $COLORSFILE |grep :|awk '{print $1}'|tr '\n' ' '`);
for PRESET in `echo ${CGARRAY[@]}` ; do
echo $Number. $PRESET
Number=`expr $Number + 1`
done
LASTCHOICE=`expr $Number - 1`
echo -n "x. Exit
Enter selection or x to quit: "
read answer
echo 0-$LASTCHOICE
case $answer in
#for now there can only be 100 presets
[0-9]|[0-9][0-9])
if [ "$answer" -gt "$LASTCHOICE" ] ; then
echo "Not a valid choice, should be between 0 and $LASTCHOICE"
read junk
fi
COLOR=${CGARRAY[$answer]}
TC=`grep -w ^$COLOR $COLORSFILE|awk '{print $2}'|tr ':' ' '`
tab-color $TC
if [ ! -z "$ECHOCMD" ] ; then
echo COMMAND NOTES:
echo $ECHOCMD
read junk
fi
echo "For faster tab color run:"
echo `basename $0` -t `echo $TC|tr ' ' ':'`
read junk
;;
x|q|X|Q)
exit
;;
*)
echo "Not a valid choice, should be between 0 and $LASTCHOICE, exiting"
exit
;;
esac
else
echo "No presets defined check $COLORSFILE"
read junk
fi
}
tab-reset() {
echo -ne "\033]6;1;bg;*;default\a"
}
session-badge() {
if [ -z "$BADGE" ] ; then
echo -n "Enter badge text: "
read BADGE
fi
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "$BADGE" | base64)
}
presets() {
if [ -s $PRESETSFILE ] ; then
Number=0
clear
echo "**** Defined Presets *****"
declare -a PRESETARRAY=(`awk -F, '{print $1}' $PRESETSFILE|grep -v ^# |tr '\n' ' '`);
for PRESET in `echo ${PRESETARRAY[@]}` ; do
echo $Number. $PRESET
Number=`expr $Number + 1`
done
LASTCHOICE=`expr $Number - 1`
echo -n "x. Exit
Enter selection or x to quit: "
read answer
echo 0-$LASTCHOICE
case $answer in
#for now there can only be 100 presets
[0-9]|[0-9][0-9])
if [ "$answer" -gt "$LASTCHOICE" ] ; then
echo "Not a valid choice, should be between 0 and $LASTCHOICE"
read junk
fi
PRESET=${PRESETARRAY[$answer]}
TC=`grep ^$PRESET $PRESETSFILE|awk -F, '{print $2}'|tr ':' ' '`
PROFILE=`grep ^$PRESET $PRESETSFILE|awk -F, '{print $3}'`
ECHOCMD=`grep ^$PRESET $PRESETSFILE|awk -F, '{print $4}'`
profiles $PROFILE
if [ ! -z "$ECHOCMD" ] ; then
echo COMMAND NOTES:
echo $ECHOCMD
read junk
fi
tab-color $TC
echo "For faster preset run:"
echo `basename $0` -P $PRESET
read junk
;;
x|q|X|Q)
exit
;;
*)
echo "Not a valid choice, should be between 0 and $LASTCHOICE, exiting"
exit
;;
esac
else
echo "No presets defined check $PRESETSFILE"
read junk
fi
}
profiles() {
echo -ne "\033]50;SetProfile=$1\a"
}
profile-picker() {
clear
Number=0
declare -a PROFARRAY=(`plutil -p ~/Library/Preferences/com.googlecode.iterm2.plist |grep \"Name\"|awk '{print $3}'|tr -d '\n'|sed s/\"/\ /g`);
echo "**** Select Profile *****"
for PROFILE in `echo ${PROFARRAY[@]}` ; do
echo $Number. $PROFILE
Number=`expr $Number + 1`
done
echo -n "x. Exit
Enter selection or x to quit: "
read answer
case $answer in
[0-9])
profiles ${PROFARRAY[$answer]}
;;
x|q|X|Q)
exit
;;
*)
echo "easy tiger, exiting"
exit
;;
esac
}
##############################################################
#menu
menu() {
while true ; do
clear
echo -n "**** Iterm settings menu *****
1. Presets
2. Profiles
3. Tab colors
4. Session badge
5. Tab reset
x. Exit
Enter selection or x to quit: "
RETURN=$1
read answer
case $answer in
1)
presets
;;
2)
profile-picker
;;
3)
tab-color-picker
;;
4)
session-badge
;;
5)
tab-reset
;;
x|q|X|Q)
exit
;;
*)
echo "Not a valid choice, exiting"
exit
;;
esac
done
}
while getopts ":b:P:p:t:R:" opt; do
case $opt in
b)
#should error check
BADGE=$OPTARG
session-badge $BADGE
exit
;;
P)
if [ -s $PRESETSFILE ] ; then
PRESET=$OPTARG
#verify preset exists
if grep -q ^$PRESET, $PRESETSFILE ; then
TC=`grep ^$PRESET, $PRESETSFILE|awk -F, '{print $2}'|tr ':' ' '`
PROFILE=`grep ^$PRESET, $PRESETSFILE|awk -F, '{print $3}'`
ECHOCMD=`grep ^$PRESET, $PRESETSFILE|awk -F, '{print $4}'`
profiles $PROFILE
tab-color $TC
if [ ! -z "$ECHOCMD" ] ; then
echo COMMAND NOTES:
echo $ECHOCMD
read junk
fi
else
echo "Preset $PRESET not found in $PRESETSFILE"
echo -n "Current presets are: "
grep -v ^# $PRESETSFILE |awk -F, '{printf"%s ", $1}'
echo
fi
else
echo "No presets defined, check $PRESETSFILE"
read junk
fi
;;
p)
#should error check
PROFILE=$OPTARG
profiles $PROFILE
;;
t)
TABCOLOR=$OPTARG
tab-color `echo $TABCOLOR|tr ':' ' '`
;;
R)
#RESET
tab-reset
echo -ne "\033]50;SetProfile\a"
exit
;;
h|\?|*)
showhelp
exit 1
;;
esac
done
if [ -z "$PRESET" ] && [ -z "$PROFILE" ] && [ -z "$TABCOLOR" ] && [ -z "$RESET" ] ; then
menu
fi