Tmux, for fun and profit
reefpoints.dockyard.com
reefpoints.dockyard.com
More over, the comments here are mostly tangential to the article (except in the sense that they involve the word tmux).
Am I totally wrong? Can everyone else see into this article where I can't?
Does anyone else do something like this?
> Does anyone else do something like this?
Yup - I do exactly this for about the last year, and it works as you describe. Long-lived IRC sessions, all of my editing windows open as I like them. You can have nice monitor/chair/keyboard setups at work and home. I find I don't have much use for a laptop any more. If your Windows/ubuntu desktop install breaks, you can reinstall quickly and get back to where you were.I've also experimented with Cloud9 to some success, but it will depend on the nature of what you're doing.
I've got a linode box running arch. I configured it with all my dev needs. I'm currently in university and I spend a good amount of time at school, bouncing between labs and then also working from home.
Right now the process is simply:
ssh me@mydomain.com
tmux attach
Up comes a familiar |- split console with vim running in a window, a terminal at the root of whatever project I'm working on and the server output of that project below it. If I have to leave suddenly, Ctrl+A+D and walk away. It'll be there when you log in next time.It also has huge advantages if you're working remotely with teams or just want to launch stuff. I have nginx already configured and running. When I need to launch a new project:
1) Go to the Linode DNS Manager and setup a new subdomain
2) Go to /srv/http and git clone my project
3) Edit my nginx.conf, reboot nginx and done.
Some stuff worth checking out:
* https://github.com/thoughtbot/dotfiles
* http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-edi...
Edit: formatting
tmux and screen both have upsides and downsides for pair programming. Ones that I know of:
1. screen requires itself to be setuid root for session sharing. This is security issue to say the least. The frustrating part of this is that screen explicitly checks that that uid == 0. This means that, even if you can iron out all of the permissions issues between you and your partner without needing root access, screen will only accept suid root as the solution.
2. When you are screen sharing in tmux, the configuration used is the configuration of the person hosting the session. This can suck if you have a lot of non-standard bindings, because it forces the person you're pairing with to know them too. screen allows you to both use your own configurations while being connected to the same session.
> if you are doing software development on a
> system with any security requirements at all,
> you have already lost
Could you expand on how security and development are diametrically opposed to each other?If my development server is exposed to the Internet and I do something like disable root logins in ssh, why/what have I 'lost?'
Specifically: dickering over whether or not to make screen suid root on your dev boxes is an exercise in needless optimization.
But isn't running applications only as regular users just that, limiting exposure?
> Specifically: dickering over whether or not to make
> screen suid root on your dev boxes is an exercise
> in needless optimization.
Are you speaking from the point of view of a 13 person startup, a 200 person business or a Fortune 500 corporation?What we came up with is creating a new "pair user" and running tmux within that.
The configuration wasn't a problem for us since one of us hadn't ever used tmux and had therefore had no opinion.
> Both pairs get access to whatever user starts tmux
IIRC, if you 'host' a (gnu) screen session, then your pair will create new shells as your user. This is not a tmux-only issue. > What we came up with is creating a new
> "pair user" and running tmux within that.
That's an idea that I had, but hadn't attempted to look into yet. This also gets around the screen suid root issue (though not necessarily the config issue), if you're both logged in as the same user. How has this been working, any caveats? > The configuration wasn't a problem for us
> since one of us hadn't ever used tmux and
> had therefore had no opinion.
I use ` instead of C-a/C-b in both screen and tmux, so it could be a bit jarring to others.I'm not sure why you need to set suid on tmux. Before we created the pair user I just used the -S option to specify a socket path and then chmoded the created socket so my pair could access it.
So far so good with the new pair user. The only thing that's different is that to push our changes up to the main repo we need ssh keys and we haven't gone through the trouble of creating a new ssh key for the pair user and adding it to our teams github repo, so we have to git push and pull from a non-pair login. That can be fixed when it gets annoying but so far I'm always logged in to that machine as myself as well as the pair user so I can just switch tabs and git push/pull when needed.
> I use ` instead of C-a/C-b in both screen and tmux, so it could be a bit jarring to others.
I use C-\ myself since C-a and C-b are both prominent Emacs keys.
> I'm not sure why you need to set suid on tmux
I guess I should have been clearer: > This also gets around the "GNU screen" suid root issue
You can easily fix this. You can:1) Use a combination of ssh-agent fowarding and manually exporting the $SSH_AUTH_SOCK variable to switch between two users' ssh-agent sockets.
2) Each user commits from a separate window/shell. Each window/shell has a separate ssh-agent running in it, with that user's ssh key ssh-add'd to it.
Though, options 2 is less secure.
3) Tmux sessions are restricted to the size of the smallest client connected to the session. We've recently started using it at work and it works fine for 2 of us, but 2 others found that the resolution differences between their 13" and 15" macbooks means that the 13" sets the tmux session size so the 15" doesn't use the whole screen.
Who cares if I press cmd-t to open a file or my pair prefers to open a file with cmd-shift-n? Just send me the action that a file was opened.
I wrote up my detailed thoughts on fixing remote pair programming here.
> Who cares if I press cmd-t to open a file or my pair
> prefers to open a file with cmd-shift-n? Just send
> me the action that a file was opened.
I don't think that this was an affirmative design decision. I think it has to do with the architecture of software, and is merely a side-effect of that architecture. Pair programming isn't the main use-case for terminal multiplexers.Yes and no. Would be really fun for five minutes and really irritating for the rest of the time.
set -g mode-mouse on
setw -g mouse-select-window on
setw -g mouse-select-pane on
This particular configuration will allow you to scroll, select text and focus windows and panes with just a mouse click.When you click-drag you're now triggering a tmux selection, not the native terminal-emulator highlight. This is a big problem because the emulated variant is slow and behaves nothing like the real thing.
To my understanding this is also a problem that can't be solved without further terminal emulator support. As it stands the remote application (tmux) can either receive all mouse-events or none of them.
This means you have to choose between scroll-wheel support plus broken text-selection - or no scroll-wheel support.
Sadly not for me. I'm a die-hard vim-user but I can't live without my scroll-wheel in the terminal.
I have following in my .tmux.conf:
set -g history-limit 1000
# See https://wiki.archlinux.org/index.php/Tmux#Scrolling_issues
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
Now I can scroll using "scroll bar" which is acceptable for me. Plus I also get native text-selection."The one disadvantage of everyone at DockYard working remotely is that you can't just turn around and ask someone to come to your desk to pair up. Tmux allows multiple users to connect to a specific session. With a bit of dynamic DNS magic, port forwarding, and ssh tunneling, multiple people can connect to the same tmux session, work in the same vim window, and see the same development server."
...
"With a tmux, ssh port forwarding, and Google+ Hangout, you can create a useful pair programming environment with your remote coworkers. We find this setup very effective and use it often to work together and tackle an issue."
We had an article recently about (technical) books being blown up to fill pages - this obviously wasn't.
I don't doubt that this might be a great work, but I have to admit that I felt the '88 pages?' thought coming up. The price isn't too bad. I just found out, while checking out the pragprog site, that I fell for the 'Seems thin' thing. Maybe a conditioning I need to correct - I don't know.
So has screen and has been for years. tmux just had it first.
> a saner config
I never had any trouble configuring screen to do anything I needed.
Can you give a practical example of what somewhat important for the average user you can do in tmux with less effort than in screen?
Apart from this, most of the advantages are only noticeable in a multi-user setup. The socket-based session sharing is great, (it just uses unix permissions) and the fact that it automatically resizes to the smallest display is a huge usability improvement. When we paired with screen we would always have to jump through hoops to make sure the guy with the smaller display joined last or he'd be unable to see everything.
2. tmux has vertical splits. Yes, screen has these, but they require you to patch/build your own screen. I've yet to come across a patched screen that has vertical split support.
3. tmux can integrate scrolling with iTerm2 (IIRC, there may also be some urxvt integration, but you'd have to verify that).
4. In tmux, splits are first-class citizens. You can do "C-b <space>" to switch between 'layouts' much in the way that you would in a tiling window manager like xmonad.
5. tmux remembers your splits/layouts when you detach/reattach. Screen doesn't last I checked.
6. tmux has a 'show-messages' command that has a log of all messages that it showed at the bottom, so that you can view them if something popped up that you missed.
7. I like the config format better. I was able to convert my highly modded screen config to tmux in an hour or so, and the config file is much smaller/simpler.
8. When scrolling in copy mode it tells you where you are in the scrollback buffer (e.g. "0/32").
9. tmux has this (from the manpage):
has-session [-t target-session]
(alias: has)
Report an error and exit with 1 if the
specified session does not exist. If it
does exist, exit with 0.
10. Also this: respawn-window [-k] [-t target-window] [shell-command]
(alias: respawnw)
Reactivate a window in which the command has exited (see the
remain-on-exit window option). If shell-command is not given, the
command used when the window was created is executed. The window
must be already inactive, unless -k is given, in which case any
existing command is killed.I just fired up two instances of Putty and see my keystrokes replicated within a second.
And that book doesn't understand anything about tmux and why it came about.
And what about 'tmux and why it came about' is missing from the book, in your opinion?
Also, mouse-free environment is not just a concept, and most certainly not retarded. Care to elaborate why you think that?