# Enable 256 color capabilities for appropriate terminals

# Set this variable in your local shell config (such as ~/.bashrc)
# if you want remote xterms connecting to this system, to be sent 256 colors.
# This must be set before reading global initialization such as /etc/bashrc.
#   SEND_256_COLORS_TO_REMOTE=1
#
# To avoid enabling 256 color terminals set this variable in your local shell
# config. This must be set before reading global initialization such as
# /etc/bashrc.
#   NO_256_COLORS=1

# Terminals with any of the following set, support 256 colors (and are local)
local256="$COLORTERM$XTERM_VERSION$ROXTERM_ID$KONSOLE_DBUS_SESSION"

if [ -z "$NO_256_COLORS" ] && [ -n "$local256" -o -n "$SEND_256_COLORS_TO_REMOTE" ]; then
	case "$TERM" in
	  xterm|screen|Eterm)
		  TERM=$TERM-256color
		  ;;
	esac
	export TERM

	if [ -n "$TERMCAP" ] && [ "$TERM" = "screen-256color" ]; then
		if [[ "$TERMCAP" == *"Co#8"* ]]; then
			TERMCAP="${TERMCAP%%Co#8*}Co#256${TERMCAP#*Co#8}"
			export TERMCAP
		fi
	fi
fi

unset local256
