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:
- Input from
stdin
, output tostdout
, errors tostderr
- 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!
a+/a-
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:
a+
# !/usr/bin/env rc sed 's/^/ /'
a-
# !/usr/bin/env rc sed 's/^ //'