I am a system admin turned developer and tmux has helped me in every stage of my career so far. Such is the power of tmux.
The coolest thing that sets tmux apart from advanced terminals with tabs and panes is that it doesn't need a window manager. You can use it even on machines without a GUI or in an SSH session to a remote server.
tmux covers a vast range of use cases. However, here in this post I'll highlight some of the coolest features and use cases tmux offers for developers and try to give you the "push" to make it a part of your toolbox if you haven't already done so.
Note: I won't be talking about how to use tmux as there are lots of posts and tutorials doing just that. Instead, I'll focus more on explaining how I use tmux personally as a developer that might be useful for you to know.
So here they are.
This is probably the most common use case of tmux for developers. It's as easy as just firing up the tmux session and open multiple panes. A bigger one for your favorite terminal text editor, one for your favoring shell, one running the app you are working on in watch mode, one running the REPL shell of the language you are using.
Most developers take it a bit further and automate the process of creating the IDE like environment with hacks like these:
a. Creating an alias such as:
alias project='tmux new-session vim \; split-window -v python \; split-window -h \;'
b. Creating a shell script like:
#!/bin/sh tmux new-session -d 'vim' tmux split-window -v 'ipython' tmux split-window -h tmux new-window 'mutt' tmux -2 attach-session -d
c. Writing different tmux source files like:
#session1 new -s SessionName -n WindowName Command neww -n foo/bar foo splitw -v -p 50 -t 0 bar selectw -t 1 selectp -t 0
And bind the session with
bind S source-file ~/.tmux/session1
So here's how I prefer to create the IDE environment specific to a project. For this I use tmuxp and declare the window and pane settings in a YAML file in the project folder like this:
# https://github.com/tmux-python/tmuxp session_name: myapp-dev windows: - window_name: app layout: tiled panes: - redis-server # Redis server - sleep 1 && make run # Application - ipython # REPL shell - sleep 0 # Default shell - vim # Editor
Note: Not exactly. I kept it simple to convey the message.
When you detach from a tmux session and log out of the machine, it doesn't exit. It continues running in the background so that you can come back anytime, log in and run
tmux attach to continue doing your work. If you left some task running in the tmux session, it will continue running in the background.
Many developers have to work on a remote machine using SSH to log in to the server. So with no GUI, they don't get terminal with switchable tabs and panes. Well actually, they do. With tmux. This way you don't have to use multiple SSH sessions to have multiple windows. Only one SSH session is enough.
When used with interactive commands like
watch, etc., you get real-time status of something happening on your machine. You can open multiple panes of such monitors organised into panes on a window named "monitor" and your IDE environment on a window named "app" all into one single tmux session.
So I think that's all for now. Although there are tons of other use cases of tmux for developers, these are my personal favorites.