Fall back to various degrees of xterm if the inherited TERM variable
isn't usable.
This should be thought of as a last resort. In general it is a bad idea
to try to overrule TERM.
export TERMINFO=${PROFILE_HOME:-~}/.terminfo
+
+# Cygwin MinTTY.
+[ "$OS" = "Cygwin" -a "$TERM" = "xterm" ] && export TERM=putty-256color
+
+# Check the terminal is valid.
+while [ -z "$(tput longname 2>/dev/null)" ]; do
+ case $TERM in
+ xterm-256color) export TERM=xterm-88color;;
+ xterm-88color) export TERM=xterm-color;;
+ xterm-color) export TERM=xterm;;
+ xterm) break;;
+ *) export TERM=xterm-256color;;
+ esac
+done