Home | Articles | CV (pdf | short)
<2012-11-02> by Lorenzo

Useful scripts - a+/a-

This is the first post of a series describing simple scripts that I wrote to ease my life as a programmer.

They are implemented in various languages (python, bash, go) and thought to be used in Linux. Some of them are "general purpose", while others are specifically designed to interface other tools I use (for example, acme.)

All of them tend to have the following properties:

These properties allow the scripts to remain very simple, be composable and easy to remember.

They are available on github: fork & hack at will!


In this post I'll describe a very simple script, a+, and its counterpart a-. They are the first I wrote when I started using acme.

a+ indents every line of stdin by 4 spaces. a- "de-indents" it by the same amount. The amount of spaces (4) is fixed (to resist the temptation to change it), and indentation is done with spaces and not tabs.

The code is trivial: it uses sed and rc, the Plan9's shell ported to *nix (although, in this case, any shell would do.) Here it is:


# !/usr/bin/env rc  

sed 's/^/ /'


# !/usr/bin/env rc  

sed 's/^ //'