Tmux scripting

I’ve been using tmux for a while no to manage my terminal sessions. One thing I kept on doing was after starting tmux that I would be manually adding windows, splitting them and issuing commands in each pane such as echoing the contents of log files with tail -f.

I had heard about scripting tmux before but never really looked into it yet, until now. Since I solely use the key bindings I had to figure out how to issue these commands without them. Turns out this is pretty easy and it’s documented in the man page.

Here’s an example of a tmux script I just added to Maximus-Web.

#!/bin/bash
SESSION=$USER

tmux -2 new-session -d -s $SESSION

# Setup a window for tailing log files
tmux new-window -t $SESSION:1 -n 'Logs'
tmux split-window -h
tmux select-pane -t 0
tmux send-keys "tail -f /vagrant/maximus.log" C-m
tmux select-pane -t 1
tmux send-keys "tail -f /vagrant/maximus-worker.log" C-m
tmux split-window -v
tmux resize-pane -D 20
tmux send-keys "tail -f /vagrant/maximus-mojo.log" C-m
# Setup a CoffeeScript compiler/watchdog pane
tmux select-pane -t 0
tmux split-window -v
tmux resize-pane -D 20
tmux send-keys "coffee -o /vagrant/root/static/js/ -cw /vagrant/root/coffee/" C-m

# Setup a MySQL window
tmux new-window -t $SESSION:2 -n 'MySQL' 'mysql -uroot'

# Set default window
tmux select-window -t $SESSION:1

# Attach to session
tmux -2 attach-session -t $SESSION

You can view the (up to date) origin of this script at GitHub.

So what exactly does this script do?

  1. It creates a new tmux session.
  2. It creates a new window called ‘Logs’ which is split into a grid of 2×2 with the bottom 2 panes being smaller in size (height). In every pane a command is executed. For example in pane 0 the command tail -f /vagrant/maximus.log gets executed.
  3. A second window called ‘MySQL’ is created which runs the mysql -uroot command.
  4. Then we switch back to the first window (actually second, as tmux pane numbers start with 0) which is the window that shows us the contents of these log files.
  5. Finally we attach to the tmux session.

The added benefit of this small script is that from now on all I have to do is run it and my tmux session will be configured for this specific project (Maximus in this case).

I’ve also found some other useful tmux resources as well which are listed below:

DiggEmailRedditShare

Disabling hiberfil.sys on Windows 7

Hibernation is enabled by default on Windows 7 and Vista. But on a desktop system you usually don’t make use of hibernation. To disable it run a command line prompt (Windows Key + R, type cmd) and enter the following command: powercfg.exe -h off.

On systems with a lot of memory this can free up a lot of disk space.

DiggEmailRedditShare

Now using Disqus for comments

I’ve decided to move the commenting system of this website to Disqus. All existing comments are queued to be imported into Disqus. I’m not sure how long this is going to take but I expect it to be finished within a day (maybe two).

DiggEmailRedditShare

New blog design

Starting the today this blog is using a new design. I think this new design looks a lot more modern than the previous one did.

There’s still room for improvement though as a single request to the front page seems to generate over 130 HTTP requests. This is a bit too much to my taste so I’ll be looking into bringing this amount back to something more sane. Most requests are generated by the social widgets that are on my website.

Another thing I improved was adding Varnish PURGE support. By enabling that the cache will be reset every time I add or update a page. Should work for comments as well. Speaking of comments, the current system is likely to be replaced by Disqus. I’ve never really liked how the comment system works and Akismet is letting more and more spam getting through.

Also back is an RSS icon (see bottom of the site). Some of the link categories have also been removed from the sidebar, as well as the full site navigation which can be found at the top of the website.

Expect several more changes coming in the next days as I’ll be ironing out the flaws. Any comments and suggestions for improvement are more than welcome.

DiggEmailRedditShare

IRSSI: Ignore joins, parts, quits and nicks messages

I use IRC on a daily basis and my client of choice for that is Irssi. I run it on my Raspberry Pi which is always on, so I generally stay idle in the channels I’ve joined. Some channels have a lot of users connecting and disconnecting which clogs up the backlog a lot. I don’t know these users so I don’t really care who joins or parts. I’m more interested in any discussions or solutions to problems that are being asked.

To ignore these messages in Irssi you can simply issue the following command. Just make sure to replace #channel with the channel you want this setting to apply to.

/ignore -channels #channel * JOINS PARTS QUITS NICKS

If you use another IRC client I suggest you take a look at this hide join part messages for IRC clients.

DiggEmailRedditShare