Compile and run tmux with mouse support in Mac OS X

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
tar -xvf libevent-2.0.16-stable.tar.gz
cd libevent-2.0.16-stable
make && make install
cd ..
# }}}

#  This block is for tmux 1.5 only {{{
curl -L -o 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:
curl -o tmux-1.5-resolv.patch
patch -p0 < tmux-1.5-resolv.patch
make && make install
# }}}

# This block is for tmux 1.6 {{{
curl -L -o tmux-1.6.tar.gz
tar -xvf tmux-1.6.tar.gz
cd tmux-1.6
make && make install
# }}}

You'r all set, tmux is ready !

Tmux, and mouse support

Being able to use tmux with is really cool since Apple doesn't provide anything to work with several shells and split terminals but lacks mouse support. To provide mouse support to 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, 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/] #[default] Windows:'
(superflo@Marvin) (~) $ cat /usr/local/bin/
/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 + tmux + mouseterm
if has("mouse")
	set mouse=a
	set mousehide

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

[4] SuperFlo's .tmux.conf

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