Compile and run tmux with mouse support in Mac OS X Terminal.app

I — some times ago — discovered tmux[1], an awesome terminal multiplexer. I’ll try to make it short, it’s screen — so you can attach/detach sessions, session can have windows, window can have panes, etc — but it’s really really better, first, the man page is short and accurate (hello screen :o), and it has awesome features such as mouse support (clicks, drag&drop, scroll), built-in custom panes layouts, activity monitoring, multiple copy paste buffers and is really lightweight. I compiled it using my x64-macos Gentoo prefix[2] but you could also use simpler tools such as mac ports, or directly from the sources.

Compile tmux 1.5/1.6 from sources on Mac OS X 10.7 Snow Leopard

If you don’t have a valid compiler environment set up, or think you have one but encounter “C compiler cannot create executables”, follow this two steps procedure:

  1. Launch the Mac AppStore and download XCode
  2. Go into the Application folder and install XCode

If you are compiling and installing tmux for the first time, you probably need to compile libevent, otherwise, just switch to the tmux part. Each section (libevent, tmux 1.5 and tmux 1.6) are delimited by {{{ ... put stuff here ... }}}

sudo -s
mkdir /usr/local/src
cd /usr/local/src

# If you have never eared  about libevent, you probably need to compile it {{{
curl -L -o libevent-2.0.16-stable.tar.gz http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
tar -xvf libevent-2.0.16-stable.tar.gz
cd libevent-2.0.16-stable
./configure
make && make install
cd ..
# }}}

#  This block is for tmux 1.5 only {{{
curl -L -o tmux-1.5.tar.gz  http://downloads.sourceforge.net/tmux/tmux-1.5.tar.gz
tar -xvf tmux-1.5.tar.gz
cd tmux-1.5
# patch for x86_64 : Undefined symbols for architecture x86_64: "_res_9_b64_ntop"
# Source: http://jeetworks.org/node/110
curl -o tmux-1.5-resolv.patch http://jeetworks.org/sites/default/files/tmux-1.5-resolv.patch
patch -p0 < tmux-1.5-resolv.patch
./configure
make && make install
# }}}

# This block is for tmux 1.6 {{{
curl -L -o tmux-1.6.tar.gz  http://downloads.sourceforge.net/tmux/tmux-1.6.tar.gz
tar -xvf tmux-1.6.tar.gz
cd tmux-1.6
./configure
make && make install
# }}}

You'r all set, tmux is ready !

Tmux, terminal.app and mouse support

Being able to use tmux with Terminal.app is really cool since Apple doesn't provide anything to work with several shells and split terminals but Terminal.app lacks mouse support. To provide mouse support to Terminal.app in order to select panes, windows and/or to scroll, you have to install the SIMBL plugin mouseterm[3] (you could also use another terminal such as iTerm which has native mouse support, but I found out iTerm eats my CPU when it floods too much ; probably a scrollback problem, I haven't investigated). Finally, if you are interested in a sample advanced configuration, feel free to use my ~/.tmux.conf[4] as a start.

There is a simple concept you have to understand, your system has it's own buffer, when you use cmd+c/cmd+v, you are using the Mac's buffer. Tmux also has up to twenty internal buffers to copy/paste text within tmux only, it can't reach other applications (tmux internal buffers vs system buffer).

When activating mouse-select-pane, to ... well, select panes with your mouse (or touchpad) you won't be able copy text in the system buffer anymore with the mouse since the click has already been captured to select the pane. With Terminal.app, you have to keep the alt key pressed: your cursor then transforms into a crosshair and you are now able to visually select text blocks to be copied in the system buffer allowing you to paste using cmd+v.

Since >=tmux1.5, there is a really cool option mode-mouse which, if set to on, allow the mouse to enter copy mode and copy into tmux's internal buffers a selection only by dragging, or to scroll within tmux only by using the mouse wheel. You can also select any window in the bottom bar by clicking it's name with your mouse only if you activated set-option -g mouse-select-window on.

Some people hit this page while searching how to scroll in tmux and Mac OS X. You can either enter copy mode then use the arrows, page-{up,down} or your mouse or re-read the previous paragraph which explains a new automagic way to scroll available since >=tmux1.5.

If you wish to display your MacBook battery percentage in your tmux statusbar, here is my one-liner to do just that :

# relevant line from .tmux.conf
set-option -g status-left '[Battery: #(/usr/local/bin/power.sh)] #[default] Windows:'
(superflo@Marvin) (~) $ cat /usr/local/bin/power.sh
/usr/sbin/ioreg -l | awk 'BEGIN{a=0;b=0}
	$0 ~ "MaxCapacity" {a=$5;next}
	$0 ~ "CurrentCapacity" {b=$5;nextfile}
	END{printf("%.2f%%", b/a * 100)}'

Finally, you can even use your mouse inside vim since the mouse clicks and gesture can be forwarded to the applications.

(superflo@Marvin) (~) $ grep -A1 mouse .vimrc
" Yay Terminal.app + tmux + mouseterm
if has("mouse")
	set mouse=a
	set mousehide
endif

ps : I found the this script[5] which gives irssi mouse support for scrolling, it works fine with Terminal.app + mouseterm + tmux + irssi.

[1] http://tmux.sourceforge.net/
[2] http://www.gentoo.org/proj/en/gentoo-alt/prefix/
[3] http://bitheap.org/mouseterm/
[4] SuperFlo's .tmux.conf
[5] http://wouter.coekaerts.be/site/irssi/mouse

3 comments so far.

  1. Your guide is awesome, thanks so much for posting it!

  2. Horoscope du jour des sagittaires g-spot tirage de rune gratuite

Share your thoughts

*