forked from mk12/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-terminfo.sh
More file actions
executable file
·92 lines (77 loc) · 1.92 KB
/
Copy pathinstall-terminfo.sh
File metadata and controls
executable file
·92 lines (77 loc) · 1.92 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
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
supported=(
xterm-kitty
tmux-256color
)
usage() {
cat <<EOS
Usage: $0 [NAME]
Install terminfo entries
Arguments:
NAME The terminfo to install (if omitted, installs all)
Supported terminfos:
${supported[*]}
EOS
}
tmp=$(mktemp)
trap 'rm "$tmp"' EXIT
die() {
echo >&2 "$0: $*"
exit 1
}
ensure() {
if [[ $# -gt 1 ]]; then
for name; do
ensure "$name"
done
return
fi
# Clear TERMINFO to avoid a false positive for xterm-kitty when running
# within kitty (we still want to install it in ~/.terminfo, otherwise it
# doesn't work when ssh'ing to localhost).
if TERMINFO="" infocmp "$1" &> /dev/null; then
echo "$1 is already installed"
return
fi
case $1 in
xterm-kitty)
if [[ -z ${KITTY_PID+x} ]]; then
cat >&2 <<EOS
Cannot install $1 because we are not (directly) in kitty.
If this is a remote machine, run this locally to install $1 on it:
kitty +kitten ssh $(whoami)@$(hostname)
EOS
return
fi
infocmp -a "$1" > "$tmp"
tic -x -o ~/.terminfo "$tmp"
;;
tmux-256color)
case $(uname -s) in
Darwin) ;;
*) echo >&2 "I only know how to install $1 on macOS"; return ;;
esac
prefix=$(brew --prefix ncurses)
if ! [[ -d "$prefix" ]]; then
brew install ncurses
fi
"$prefix/bin/infocmp" -A "$prefix/share/terminfo" "$1" > "$tmp"
tic -o ~/.terminfo "$tmp"
;;
*) die "$1: unsupported terminfo"
esac
echo "Installed $1"
}
case $# in
0)
ensure "${supported[@]}"
;;
*)
case $1 in
-h|--help|help) usage ;;
*) ensure "$@" ;;
esac
;;
esac