dots/commonsh/02_term
2009-02-24 07:42:25 +00:00

85 lines
1.6 KiB
Bash
Executable file

#! /bin/sh
# terminal fallback stuff
fix_term ()
{
# we were requested to go on screen and we are on a mac
if ( infocmp $1 >/dev/null 2>&1 ) ; then
echo $1
else
case $1 in
rxvt|xterm?*|kterm|putty|screen)
fix_term xterm
;;
*rxvt?*|Eterm|aterm)
fix_term rxvt
;;
mlterm)
fix_term kterm
;;
screen-256colors-bce)
fix_term screen-256colors
;;
screen-256colors)
if ( infocmp xterm-256colors >/dev/null 2>&1 ) ; then
fix_term xterm-256colors
else
fix_term screen
fi
;;
screen?*)
fix_term screen
;;
putty-vt100)
echo "vt100"
;;
putty-256color)
fix_term xterm-256color
;;
*)
echo "vt100"
;;
esac
fi
}
# sorta hacky, but I cannot find a better way to do this :/
fix_terminfo_db ()
{
if [ -d "$1" ] && [ `command -v infocmp 2>/dev/null` = "$1/bin/infocmp" ] ; then
TERMINFO="$1/share/terminfo"
export TERMINFO
fi
}
if ( command -v infocmp >/dev/null 2>&1 ) ; then
# terminal surgery
case `uname -s` in
Interix)
fix_terminfo_db "/usr/local"
;;
SunOS)
fix_terminfo_db "/opt/csw"
;;
Darwin)
fix_terminfo_db "/opt/local"
;;
esac
TERM=`fix_term $TERM`
# I am sorry to hear that you are running an
# xterm that has no colors (I am looking at you solaris)
if [ $TERM = xterm ] && ( command -v tput >/dev/null 2>&1 ) && [ `tput -T xterm colors` = -1 ] ; then
# lets see what we can do about your terrible term
TERM=`fix_term xterm-color`
fi
export TERM
case $TERM in
*256*)
alias screen="screen -T `fix_term xterm-256color`"
;;
esac
fi