jasonwryan.com

Miscellaneous ephemera…

Sessions in tmux

Sessions in tmux

Now that I have been using it for several months, I have become absolutely dependent upon tmux, the terminal multiplexer. It is both ruthlessly efficient, and can be configured to match exacting requirements. One of those options is to initialize sessions with a preloaded window configuration. After reading the man page (which, truth be told, could be a little clearer) and some experimentation, I have worked out how to set up my tmux sessions how I want them. I have just updated the Arch Wiki tmux entry, so thought I would share it here.

The relevant part of my config file looks like this:

1
2
3
4
5
6
7
# session initialization
new  -n TTYtter /home/jason/Scripts/ttytter.pl
neww -n irssi /home/jason/Scripts/startirssi.sh
neww -n ncmpcpp/vifm ncmpcpp
splitw -v -p 50 -t 0 vifm
neww -n bash bash
selectw -t 1

Which, when I start tmux with the attach (or a) option, gives me the following window layout:

  • TTYtter
  • irssi
  • ncmpcpp/vifm     # window split vertically in half, ncmpcpp on top of vifm
  • bash

The selectw option means that the default view is TTYtter.

Simple.

Command Line Notes

image

A couple of weeks ago, I came across these simple bash functions written by Jack Mottram of One Thing Well for managing text notes.

The functions as described in the article are so:

1
2
3
n() { $EDITOR ~/notes/"$*".txt }

nls() { ls -c ~/notes/ | grep "$*" }

Unfortunately, the second function – for retrieving the list of files in the notes directory has two significant shortcomings — it uses ls1 and it will only list files in the top level directory. If you are an inverterate note taker, this plainly won’t scale.

My first attempt at hacking a solution yielded this little beauty:

1
2
nls() { tree -Cu --noreport ~/.notes | awk '{print $2,$3}' | tr -d [:digit:] | sed 's/]//'\ 
| cut -d"." -f1 ; }

Which removes ls from the function and allows nested directories, but is needlessly complex and, with four pipes, hideously inefficient inelegant.

After reading up on Awk, particularly Bruce Barnett’s primer, I arrived at something marginally longer but relying solely on the awesome power of awk to make the various transformations I was seeking…

1
2
nls() { tree -CR --noreport ~/.notes | awk '{ if (NF==1) print $1; \
else if (NF==2) print $2; else if (NF==3) print "  "$3 }' ; }

An added advantage is that it is scalable irrespective of how deep the directories go. I’m sure that with some more awk-foo I could write a more effective set of conditionals, but this seemed a pretty good start for a simple note taking utility.

Updated 3/11/10

To remove a little of the visual clutter, I amended the awk script to strip the .txt extensions from the output.2

1
2
nls () { tree -CR --noreport ~/.notes | awk '{ if ((NR > 1) gsub(/.txt/,"")); \
if (NF==1) print $1; else if (NF==2) print $2; else if (NF==3) printf "  %s\n", $3 }' ;}

And if you really want this to work well, create your .notes directory in a dropbox folder and symlink to it from ~/.notes.

Notes
  1. See Parsing ls on Wooledge Wiki.

  2. Obligatory “after” screenshot:

5 Alternate Mail Clients

Rather than just download Thunderbird, you can always install something a little more interesting that will a) provide hours of fun setting up and configuring so that it works exactly the way you want it to, and b) will free you of the rodent…

  • Mutt - a small but very powerful text-based mail client for Unix operating systems. Eminently extensible and configurable. mutt + imap + gmail ftw!
  • Alpine - based on the Pine® Message System. Not as intimidating for the novice as mutt…
  • Sup - a console-based email client for people with a lot of email. “The goal of Sup is to become the email client of choice for nerds everywhere”
  • Notmuch - an answer to Sup. Still in the early stages of development, there are two user interfaces available for it, one for vim and one for those poor benighted souls still using emacs…
  • Cone - a screen-oriented E-mail/News reader and writer. Cone contains an experimental implementation of a new remote mail access protocol, SMAP