-
Notifications
You must be signed in to change notification settings - Fork 13
/
settitle
executable file
·70 lines (65 loc) · 1.62 KB
/
settitle
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
#!/usr/bin/env bash
# settitle -- update the terminal window titlebar or window name
# # TODO: DECSWT (supported by Windows Terminal 1.21)
usage() {
echo "Usage: ${0##*/} [-arsw] <title>"
echo ""
echo "Update the terminal's window titlebar."
echo ""
echo "Options:"
echo " -a use nonstandard BEL terminator instead of ST"
echo " -r ask terminal to restore saved title"
echo " -s ask terminal to save current title"
echo " -w set tmux/screen \"window name\""
}
do_bel=0
do_save=0
do_restore=0
do_wname=0
while getopts "arsw" OPT; do
case $OPT in
a) do_bel=1;;
r) do_restore=1;;
s) do_save=1;;
w) do_wname=1;;
*) usage; exit 2;;
esac
done; shift $((OPTIND-1))
title=$*
if (( do_wname )); then
# Set tmux/screen window title
if (( do_save || do_restore )); then
echo "${0##*/}: save/restore ineffective for window name" >&2
exit 1
fi
if (( do_bel )); then
echo "${0##*/}: BEL terminator not used with this mode" >&2
exit 1
fi
if [[ $TERM- == @(screen|tmux)-* ]]; then
printf '\ek%s\e\\' "$title"
fi
elif (( do_restore )); then
# Restore (pop) window title if supported
if [[ $title ]]; then
echo "${0##*/}: cannot both restore and set new title" >&2
exit 1
fi
if (( do_bel )); then
echo "${0##*/}: BEL terminator not used with this mode" >&2
exit 1
fi
printf '\e[23;2t'
else
# Set regular Xterm window titlebar
if (( do_save )); then
# Save (push) window title if supported
printf '\e[22;2t'
fi
# XXX: Should just use BEL everywhere for better compatibility?
if (( do_bel )); then
printf '\e]0;%s\a' "$title"
else
printf '\e]0;%s\e\\' "$title"
fi
fi