Multiple Custom Commands in Shell Startup (for Terminator)
Multiplexing with a GUI
If you use the shell extensively, I hope you know terminator
by now. But, you know, this whole “writing a blog” thing will be pretty pointless if you already knew everything I wanted to say, so… I should probably elaborate.
Whenever I use a shell, I probably need several side by side - In one, I compile; in a second, I check the system log; in a third, I have an SSH to a staging server; in a fourth, I have htop
showing how awesome my machine is at compiling - etc. You know what they say about shell windows - “Bet you can’t have just one!”. Wait… Nevermind.
terminator
supports split windows, tabs, profiles, saved layouts (which I’ll come to in a minute), etc. I use it every day.
If you look online for this issue, you’ll probably come across recommendations for screen
or tmux
. These tools are useful, but require lots of key combination memorization. I’m all in for using the keyboard (I’m writing this blog post using Vim, although mainly because I haven’t figured out how to quit), but I prefer to have a GUI option.
I recommend you head down to their website RIGHT NOW and install it on your system. If you’re on Ubuntu, the command is:
Custom Layout
One of terminator
s useful features is layouts. When you work on certain project, you usually want the same layout of windows - one in the root of your projects to run your build system and / or source control commands, one in the build directory, and the last one tail -f
ing the system log. terminator
lets you save these structures as layouts.
This is how the terminator
layout setting window looks like:
(The photo is courtesy of this Stack Overflow question)
See that little “Custom command” textbox on the upper right side? terminator
will run that command in the selected window. Most probably, we’ll want to run some shell (zsh
for me) with a couple of commands specific to the window, like setting a Python virtualenv, running a certain script, etc.
However, there are a several problems with this feature.
Continuous Commands - say you want to automatically start a continuous command, for example
tail -f /var/log/syslog
.terminator
will run it just fine, but if for some reason you want to end the command (to restart it, or run a different command in the same windows) - as soon as you press Ctrl+C, the window will disappear.Side Effects - a common command I like to run automatically for a given project is to set an enviornment for it. For me, it usually means activating a certain Python virtualenv with the
workon <project>
command. However, entering that command forterminator
to run, will not take effect even if I tell it to runbash
afterwards.History - let’s say I want to automatically run some DB migration on my Django project automatically when starting
terminator
. I’ll probably want to run them again while working, so I want to be able to search backwards in my shell history for the command (in my terminal, this happens automatically if I start to type and then press the ‘up’ key. Commands entered here will not appear in the shell history.
To solve all of these problems, I put the following script in my ~/.zshrc
(or ~/.bashrc
, if you’re so inclined):
And the following snippet goes in the ‘Custom command’ textbox:
That’s it. You get multiple custom commands inside a shell, with easy history access. Enjoy!
Discuss this post at the comment section below.Follow me on Twitter and Facebook