-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathit2setkeylabel
More file actions
executable file
·123 lines (118 loc) · 3.06 KB
/
it2setkeylabel
File metadata and controls
executable file
·123 lines (118 loc) · 3.06 KB
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
#!/bin/bash
# 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
}
function show_help() {
echo "Usage:" 1>& 2
echo " $(basename $0) set Fn Label" 1>& 2
echo " Where n is a value from 1 to 20" 1>& 2
echo " $(basename $0) set status Label" 1>& 2
echo " Sets the touch bar status button's label" 1>& 2
echo " $(basename $0) push [name]" 1>& 2
echo " Saves the current labels with an optional name. Resets labels to their default value, unless name begins with a "." character." 1>& 2
echo " $(basename $0) pop [name]" 1>& 2
echo " If name is given, all key labels up to and including the one with the matching name are popped." 1>& 2
echo "" 1>& 2
echo "Example:" 1>& 2
echo "#!/bin/bash" 1>& 2
echo "# Wrapper script for mc that sets function key labels" 1>& 2
echo "NAME=mc_\$RANDOM" 1>& 2
echo "# Save existing labels" 1>& 2
echo "$(basename $0) push \$NAME" 1>& 2
echo "$(basename $0) set F1 Help" 1>& 2
echo "$(basename $0) set F2 Menu" 1>& 2
echo "$(basename $0) set F3 View" 1>& 2
echo "$(basename $0) set F4 Edit" 1>& 2
echo "$(basename $0) set F5 Copy" 1>& 2
echo "$(basename $0) set F6 Move" 1>& 2
echo "$(basename $0) set F7 Mkdir" 1>& 2
echo "$(basename $0) set F8 Del" 1>& 2
echo "$(basename $0) set F9 Menu" 1>& 2
echo "$(basename $0) set F10 Quit" 1>& 2
echo "$(basename $0) set F11 Menu" 1>& 2
echo "$(basename $0) set F13 View" 1>& 2
echo "$(basename $0) set F14 Edit" 1>& 2
echo "$(basename $0) set F15 Copy" 1>& 2
echo "$(basename $0) set F16 Move" 1>& 2
echo "$(basename $0) set F17 Find" 1>& 2
echo "mc" 1>& 2
echo "# Restore labels to their previous state" 1>& 2
echo "$(basename $0) pop \$NAME" 1>& 2
}
## Main
if [[ $# == 0 ]]
then
show_help
exit 1
fi
if [[ $1 == set ]]
then
if [[ $# != 3 ]]
then
show_help
exit 1
fi
print_osc
printf "1337;SetKeyLabel=%s=%s" "$2" "$3"
print_st
elif [[ $1 == push ]]
then
if [[ $# == 1 ]]
then
print_osc
printf "1337;PushKeyLabels"
print_st
elif [[ $# == 2 ]]
then
if [[ $2 == "" ]]
then
echo "Name must not be empty" 1>& 2
exit 1
fi
print_osc
printf "1337;PushKeyLabels=%s" "$2"
print_st
else
show_help
exit 1
fi
elif [[ $1 == pop ]]
then
if [[ $# == 1 ]]
then
print_osc
printf "1337;PopKeyLabels"
print_st
elif [[ $# == 2 ]]
then
if [[ $2 == "" ]]
then
echo "Name must not be empty" 1>& 2
exit 1
fi
print_osc
printf "1337;PopKeyLabels=%s" "$2"
print_st
else
show_help
exit 1
fi
else
show_help
exit 1
fi