thinking sysadmin

qstat -u aleonard -s z

Two Useful Tools: ack and autojump

2 comments

A recent answer to a question on Quora – What are some time-saving tips that every Linux user should know? – suggested two tools I’ve found very useful: ack and autojump.

Ack advertises itself as “better than grep” and is “designed for programmers with large trees of heterogeneous source code.” In a nutshell, it’s a more straightforward tool for searching only one type of code file than combining “find” and “grep”. Here’s an example of it in action, searching only PHP files (.php .phpt .php3 .php4 .php5 .phtml) for the string “phpinfo” – and imagine the output with color highlighting:

> ack --php phpinfo      
utilities.php
141:	   Gather phpinfo into a string variable - This has to be done before
147:	phpinfo(INFO_MODULES);

phpinfo.php
1:<?php phpinfo(); ?>

I have a fork of ack on Github – a very trivial fork, adding only support for Puppet (.pp) files. (I did submit a pull request to the author, but he quite reasonably rejected it as he is focused on version two, which will have new features for handling file types.) (Update: See comment below from ack’s creator on a better way to do this.)

Autojump is “a cd command that learns.” As in, with minimal input, it picks the right directory to jump to based on your previous actions:

> pwd
/tmp
> j git
/haiku/home/anl/git
> pwd
/haiku/home/anl/git

“jumpstat” tells you the relative ranking of directories in the autojump database:

> jumpstat
1.0:	/haiku/home/anl/git/hrc-puppet/modules/puppet
2.0:	/haiku/photos/andy/201012
2.0:	/cloud/leonard/photos/201012
2.0:	/opt
2.0:	/haiku/home/anl/git/hrc-puppet/modules/apt
2.0:	/home/anl/Desktop
[...]

Tab completion works, too; typing “j user” and three tabs yields the following for me:

> j user__
user__1__/haiku/home/anl/git/hrc-puppet/modules/users
user__2__/haiku/home/anl/git/ext/puppet/modules/users

Installation is straightforward, with an install script and manual instructions. To scratch my own particular itch, I have a fork on Github that adds an install script for non-root users. (I haven’t submitted a pull request, and I doubt I will, as I don’t think my code is particularly useful to most folks; it also isn’t particularly polished.)

Written by Andy

January 8th, 2011 at 3:51 pm

Posted in Applications

Tagged with , , , ,

2 Responses to 'Two Useful Tools: ack and autojump'

Subscribe to comments with RSS or TrackBack to 'Two Useful Tools: ack and autojump'.

  1. [...] This post was mentioned on Twitter by Andy Leonard, Xinity Bot. Xinity Bot said: Two Useful Tools: ack and autojump (thinking sysadmin) http://bit.ly/f7dFBB [...]

  2. ack does support adding filetypes already. In your case all you need to do is create a ~/.ackrc file with

    –type-set=puppet=.pp

    My comment about “better handling” didn’t mean that you couldn’t do it now, just that I’m putting all file type stuff on the back burner anyway.

    Andy Lester

    8 Jan 11 at 8:19 pm

Leave a Reply