-
Notifications
You must be signed in to change notification settings - Fork 5
/
term
36 lines (31 loc) · 1.27 KB
/
term
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
#!/bin/bash
# after: bootstrap
# Try to fix broken $TERM
if [ -n "$TERM" ] && command -v tput &>/dev/null; then
while ! tput longname &>/dev/null; do
[ -t 2 ] && echo -n "TERM=$TERM didn't work out..." >&2
# if we ship a source for $TERM, and it's compiled yet, compile it and try again
if [ -f "$HOME/.terminfo.src/$TERM.terminfo" ] && ! [ -f "$HOME/.terminfo/${TERM:0:1}/$TERM" ]; then
tic "$HOME/.terminfo.src/$TERM.terminfo"
if tput longname &>/dev/null; then
[ -t 2 ] && echo "compiled ~/.terminfo worked!" >&2
break
fi
fi
# if -256color, try lower color version
if [[ "$TERM" = *-256color ]] && tput -T"${TERM%-256color}" longname &>/dev/null; then
export TERM=${TERM%-256color}
[ -t 2 ] && echo "using TERM=$TERM instead." >&2
break
fi
# hmm, well if it's not linux, try that
if [ "$TERM" != linux ] && tput -Tlinux longname &>/dev/null; then
export TERM=linux
[ -t 2 ] && echo "using TERM=$TERM instead." >&2
break
fi
# finally, fallback on vt100
export TERM=vt100
[ -t 2 ] && echo "falling back to TERM=$TERM instead." >&2
done
fi