column
The other day I wanted some prettier (tabularized) output and of course someone has already wanted this and of course there are tools for that
bash_completion
This is so frakking cool! I’ve built this little shellscript “vault.sh” which is a simple wrapper script for mounting and unmounting encfs mounts.
It takes two parameters: operation and target, where operation can be one of “lock” and “unlock”, and target—at present—resolves to “thunderbird” (signifying my .thunderbird directory).
Since I intend to expand this with more encrypted directories as I see fit, I don’t want to hard-code that.
What I did want, however, was to be able to auto complete operation and target. So I looked around, and found this post, and although I couldn’t derive enough knowledge from it to solve my particular problem, having multiple levels of completion, the author was gracious enough to provide references to where s/he had found the knowledge (here, here and here). That second link was what did it for me.
My /etc/bash_completion.d/vault.sh now looks like this:
_vault()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
first="lock unlock"
second="thunderbird"
if [[ ${cur} == * && ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${second}" -- ${cur}) )
return 0
fi
if [[ ${cur} == * && ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${first}" -- ${cur}) )
return 0
fi
}
complete -F _vault vault.sh
And all the magic is happening in the two if-statements. Essentially: if current word (presently half typed and tabbed) is whatever, and this is the second argument to the command, respond with suggestions taken from the variable $second.
Otherwise, if current word is whatever, and this is the first parameter, take suggestions from the variable $first.
Awsum!
awk for great good
Another great use for awk: viewing selected portions of source code. For instance, in Perl, if you just want to view a specific subroutine, without getting distracted by all the other crud, you could do: $ awk '/sub SomeSubName/,/}/' somePerlModule.pm
Links
If PHP were British, perhaps it’s just me, but I find it hilarious.
PayPal just keeps working their charm…
Preserving space, neat!
Fuzzy string matching in Python
If you aren’t embarrassed by v1.0 you didn’t release it early enough
The makers schedule, oldie but goldie
CSS Media Queries are pretty cool
Static site generator using the shell and awk
Comparing images using perceptual hashes

My software stack revisited – Programming
Friday, December 24th, 2010Programming is one of my primary interests, mainly because it allows me to stimulate my brain with solving problems, but also force it to think in new ways.
Languages
I started programming in PHP, picked up Java and Erlang during classes at ITU, picked up Python on my own during my studies at ITU, and my latest addition would be shell scripting.
Slightly tangent to the topic are the markup languages I have picked up as well, html and css in high-school and LaTeX at ITU. I dabbled around for a while with both creole and markdown, but that didn’t last long.
Editor / IDE
My first and foremost tool of choice given nearly any situation will be (g)vim. The only two exceptions I can think of off the bat is Java (for which I use Eclipse and if I need to write a whole lot of text, with minimal distraction (more on that later).
The pragmatic programmers recommend learning one text-editor, and learn it well. If the name of that editor is vim, emacs, kate, gedit, or whatever, I really don’t care. Just pick up one that fits you, and LEARN IT WELL!
I have extended vim with a couple of plugins, the most prominent being NERD Commenter, matchit, snipMate and sparkup. There are at least two more plugins, but I will write more about those later.
And for Python, I usually install the IPython interactive prompt as it is a fair bit more useful than the standard python-prompt.
Version Control
While studying at ITU I had my eyes opened about the wonderful concept of version control.
I was first exposed to SVN, and while quite capable, I figured it was too much of a hassle to set it up myself, since that would require the presence of a server somewhere to host the SVN repositories.
But then mercurial entered the stage. Git or bazaar would have done the job just as good, but the people orchestrating the fourth term settled on mercurial, and it is so dead simple and still powerful enough for what I need that I haven’t had a reason to look elsewhere.
Issue tracking
For a course at ITU I tried using Mantis, a web-based bug tracker written in PHP, and while it worked well, it was a hassle to manipulate bug reports since it meant I’d have to go online and log in to yet another system.
I have however found a different solution which I am currently trying out: a plugin to mercurial called b with the tagline “distributed bug tracking”. It is a bit too early to tell if it will do, but for the time being it solves the immediate problem of having to go online somewhere to handle bugs.
Next post in line: “Office Suite” software
:wq
Tags: css, Eclipse, Erlang, gVim, html, ipython, Java, matchit, mercurial, NERD Commenter, PHP, Python, shell-script, snipMate, sparkup
Posted in English, GNU/Linux, Tools | Comments Off