For bash add to .bash_profile or whatever:
PROMPT_COMMAND="echo -ne \"\\033]0;\${USER}@${HOSTNAME}\\007\\033k\${PWD}\\033\\\\\""
For vim add to .vimrc:
if &term == "screen"
set t_ts=^[k
set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
set title
endif
autocmd BufEnter * let &titlestring = "vim " . expand("%:t") . " " . expand("%:h")
For those not familiar, to get the escape sequence ^[ in vim, press Control-V Escape.
Thanks to JohnKiller's suggestion, I realized that .bashrc executes both when a new tty is opened, and when TMUX is opened in a terminal.
For future readers: The $TMUX variable is typically referenced to see if TMUX is running at all, but you could also use "pidof tmux". The $TMUX variable will be populated with something like: "/tmp/tmux-0/default,27389,0" if TMUX is running.
In my particular case, I'm running CentOS 6, and have it set to auto-login with root since it's just a test image. I was able to do that by editing /etc/init/tty.conf:
exec /bin/mingetty --autologin root $TTY
Now that it's set to auto-login, I added the following to /root/.bashrc:
if [[ `tty` == "/dev/tty1" ]] && [[ -z "$TMUX" ]];then
tmux
fi
For newbies reading this, this says "If my terminal is terminal 1, and the $TMUX variable is zero-length, run tmux".
It's followed by:
if [[ -n "$TMUX" ]] && [[ ! -e "/root/.automatic_start_occurred" ]];then
touch /root/.automatic_start_occurred
/usr/bin/hello_world
fi
Again for newbies, this says "If $TMUX is non-zero in length, and the file ".automatic_start_occurred" does not exist (the "!" in the if statement), make the file "/root/.automatic_start_occurred" and then execute "hello_world" in /usr/bin.
This is exactly what I was looking for my system to do - After booting, TTY1 will pop up with TMUX, and the other TTYs will be left alone. When TMUX pops up for the first time, it will execute some arbitrary commands, and never do them again unless the file ".automatic_startup_occurred" is removed.
Best Answer
Tmux (and the older screen) allow one terminal session (eg. ssh connection) to act like many sessions. The panes allows sections of the terminal screen to be divided among sessions, much like windows (Mac/Win/X11.)
The most valuable feature is the ability to disconnect, and reconnect to a session, and even connect to the same session multiple times (ie. from one than one location.)