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 (
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,
All of them tend to have the following properties:
- Input from
stdin, output to
stdout, errors to
- Return zero on success, non-zero on failure
- Do one thing only
- Not too much customizable
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
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
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/^ //'