A for Alias

In Zsh (and other shells), aliases may be the most important feature for increased productivity.

A simple rule is this: the more often you run a command, the shorter it should be. I’ve written about this before, in Efficient Way to Improve Console Productivity.

I have a number of one-character aliases:

G='| glark'
H='| head'
L='| less'
M='| more'
S='| sort'
T='| tail'
h='history -5000'
l='ls -CF'

I’ll write later about those nifty uppercase ones (and yes, there is the alias “a” for “alias”, but for now, I’ll just show them with examples:

alias G -g '^.='

That was the command that I ran to generate the list above. It expands to “alias | glark -g ‘^.='”.

find src -type d S

That finds all directories and pipes them to sort.

There are three “families” of commands that I run the most often:

  • diff – diff files
  • eye – look at/in files on the command line
  • find – list all files/directories matching a pattern
  • open – open files in editor, browser
  • search – look in files

So I have been writing one-character scripts/functions (in Bash) for each of the above, where the script understands context as well as the targets.

For example, “s pluralize” run from a directory that contains a “Rakefile” will expand to search (using glark) only for Ruby files.

e program.tar.gz” is the equivalent of “tar ztvf program.tar.gz“, and “e program.zip” lists the zip file, with entries sorted by name.

d dir1 dir2” runs a recursive diff on the directories, and “d path/to/file ../dir2” will diff “path/to/file” against “../dir2/path/to/file”, if the latter file exists. I do this to avoid the tedious repetition of comparing one code base to another (such as two branches, when merging them): “diff path/to/file1 ../dir2/path/to/file1“, “diff path/to/file2 ../dir2/path/to/file2“, etc.

Although this project is in its early stage, and the output is still rough (i.e., containing debugging output), it already has been quite useful, so I thought I would share.

The project is at Github here.

Sharpening the Emacs Saw

Emacs has been my primary/only editor for around 20 years, and I’ve become more aware of how little of its power I actually use. Emacs Rocks has been very inspirational in motivating me to further explore the functionality of Emacs. Lately I’ve been applying the DRY principle to Emacs itself, where if I find myself repeating a sequence of commands (including characters) in Emacs, I’ll write a macro or snippet (using YASnippet, which I highly recommend).

Integrating this approach with the Pomodoro and/or Getting Things Done principles, whenever I find myself repeating, er, myself, I’ll stop and add that sequence as appropriate, usually as a change to either my Emacs environment or my shell (Z shell) setup. It might be a bit of a distraction, diverting my attention for a minute or two, but the benefit is that I can begin using the new shortcut immediately. In fact, to enforce the new shortcut, if I accidentally use the equivalent long sequence, I’ll back up (such as deleting the just-typed characters) and use the new shortcut instead. This helps to erase the old muscle memory and enforce good, new habits.

YASnippet is especially valuable in automatically generating the boilerplate so much required by programming languages, especially Java. Even Ruby has its own overhead, and I recently heard (I’m about eight months behind) on a Ruby Rogues podcast that essentially if a Ruby programmer is actually typing “end”, then their environment is not adequately customized. I’d add that the same would apply to curly braces in Java and other C-derived languages.

A rule of thumb I’ve read is to add one script per day, and I’d advise the same for one’s editor, whether it be Emacs or any other powerful editor that can be customized, as virtually of them can be now. PragProg now has a new Vim book, Practical Vim. I don’t know of an equivalent book for Emacs, but it seems that there would be a market for it.