robbyrussell/oh-my-zsh — pull request #2445 by andschwa (2014-01-18 23:02:26+00:00)
Title: Fixing iTerm Tmux integration (branch off upstream/master)

As per issue #1903, this actually fixes the iTerm integration. No more weird crashing.

Really I should just refactor this whole plugin, but it'll have to wait until spring break probably, or for someone to ask.

As before:

Essentially, if ZSH_TMUX_ITERM2 is set to true, the tmux plugin adds the option -CC to tmux whenever it is invoked. Enabling this also disables the loading of any "$HOME/.tmux.conf" configuration file, as they are not yet supported.
Tested working with AUTOCONNECT and AUTOQUIT.

The trick was instead of tmux attach || tmux new (which would fail because tmux attach, on failing to attach, itself tries to start the server) to check of it can attach with tmux has, and if so, attach, if not new session.