termdetect auto-detect which terminal emulator we're talking to

Termdetect is a script that auto-detects which terminal you're using (eg. Putty, Xterm, Konsole). It does its job solely by communicating with the terminal via escape codes, so it's much more reliable than $TERM. It works no matter how many SSH hops you've made.

There are various ways to use it, but one way to use it is to automatically set your $TERM:

export TERM = $( termdetect -t )

Terminals currently detected — aterm, dtterm, iterm2.app, konsole, linux (console), mosh, mrxvt, putty, rxvt, screen, securecrt, teraterm, terminal.app, tmux, VTE (Gnome Terminal, XFCE4 Terminal, Roxterm, etc), and xterm.

How does it work?

Terdetect figures out a "fingerprint" of the current terminal by sending various ANSI escape codes to the terminal and seeing how the terminal responds. It looks up the fingerprint in a database of known terminal fingerprints, and reports which terminal matches the fingerprint.

Installation

curl -L http://is.gd/termdetect -o termdetect ; chmod +x termdetect # or wget http://is.gd/termdetect ; chmod +x termdetect

Works on any Un*x or OS/X. Self-sufficient, nothing else is required.

Other ways to use it

" ~/.vimrc syntax on if & t_Co >= 256 || has ( 'gui_running' ) " your prefered colorscheme when the terminal supports 256 colors let g :solarized_termcolors = & t_Co colorscheme solarized else " your prefered colorscheme when the terminal supports 16 colors colorscheme pablo endif

Most people have learned to mistrust $TERM and terminfo, and so hard-code everything. Once you're able to trust them again, your configuration can be much more flexible and adaptive.