Minor scripts and hacks

I put minor hacks and scripts here. Some may be of use to others but me, but I expect that the majority will only be of educational or entertainment value. More fleshed-out instructive programs are in a different section.

Many of the scripts are written in rc, the command shell from the Plan 9 operating system. It is similar to classic POSIX bourne shell script, but significantly simplified and, in my opinion, improved. Should you wish to run them, you will need a port of rc to your platform. I personally use 9base, a port of many of the standard Plan 9 tools to the POSIX environment by the gentlemen and scholars at suckless.org. Beware: the reimplementation of rc for Unix by Byron Rakitzis is incompatible in many fundamental and seemingly arbitrary ways, for example by using else instead of if not as in Plan 9 rc. Sadly, this is the version you will get if you merely install the rc package in Debian. Install the 9base package instead, and add /usr/lib/plan9/bin to your path. Also read this guide to setting up Plan 9 userland tools.

8ball

Query the magic 8-ball. Prints one of the standard twenty answers on standard output.

Usage: 8ball. No arguments are accepted.

HsGrep.hs

Haskell implementation of simple regular expressions, inspired by Torben Mogensens textbook “Introduction to Compiler Design”.

Character ranges are supported through translation to alternations. Negative ranges are not supported. A backslash causes the following character to be read literally, even if it is normally syntactically significant. The full path from regular expressions over NFAs to DFAs has been implemented, and several utility functions for printing the state machines as graphs (in GraphViz format) are also provided.

If compiled as an executable, the program acts as a very simple grep clone.

andet

A script for creating aliases that are actual files in a directory (which you should then add to your PATH). This means that these aliases are visible to non-shell programs, which can be handy.

cloud

Leverage the power of CLOUD COMPUTING using standard Unix tools! Given a list of servers to which you have password-less login through ssh, YOU TOO can command the awesome power of modern round-robin cloud computing. Incorporating ideas from both CSP and cutting-edge pipelined architectures, the use of cloud in conjunction with the Unix shell permits ENORMOUS SCALABILITY when processing data sets (especially if you do not pay for the servers running the commands for you). For example, leveraging the MapReduce principle to count the files starting with vowels in a directory:

ls | cloud tr '[A-Z]' '[a-z'] | cloud grep '^[aeiouy]' \
   | cloud sed -r 's/^\([aeiouyAEIOUY]\).*/\\1/' \
   | cloud sort | cloud uniq -c

Note that only the sort and uniq commands have to wait for complete input - the rest run in parallel on a line-by-line basis. That is the power that cloud can bring to your enterprise!

Note that you have to edit the servers command in the source code to represent the machines in your own cloud (you probably do not have login rights to mine).

Usage: cloud <command>.

dmenu

Wrap sinmenu(1) in a dmenu-compatible interface.

dmenu_path_watcher

Rerun dmenu_path (reconstructing the cache in ~/.dmenu_cache) whenever a file is removed or added to a directory in PATH. Start this in the background (for example from your ~/.profile or ~/.xsession) and enjoy. Requires inotify-tools for the inotifywait program.

fixnames

Convert files names from Latin-1 to proper UTF-8.

lhscode

Extract code blocks from Literate Haskell files and print them on standard output.

Blank lines will be used to separate logical code blocks (sequences of lines starting with >, or \begin{code}/\end{code} pairs), but the contents of the blocks are printed verbatim.

Usage: lhscode [file ...], reading from standard input if no files are provided.

rmprefix.c

Strip sequence of lines of their common prefix, if any.

rmprefix reads lines on standard input, and prints them on standard output in the same order, but with their common prefix removed. This prefix may be empty, in which case output will be the same as input. No error checking is done.

Usage: rmprefix. No command line options are accepted.

roll

Roll dice. The format is the usual NdK (eg. 1d6, 2d20). No error correction is done. The dice count is optional (eg. 1d6 is the same as d6). Multiple rolls per invocation is supported, just supply more arguments.

Usage: roll NdK…

sigkill-put

Upload a single file to a server and make it readable, echoing the URL at which it is now available. This is convenient if default umask settings make just SCPing create an inaccessible file.

stashcfg

Given a program name and a configuration file name, copy the the file to the proper XDG directory and set up a symlink at its original location. Additionally, create a script $XDG_CONFIG_HOME/mklinks.sh that will re-establish the symlink if deleted.

Always run this program from your home directory.

unandet

A script for creating aliases that are actual files in a directory (which you should then add to your PATH). This means that these aliases are visible to non-shell programs, which can be handy.

x

Terrible Bourne shell script wrapper around tar vxf, that ensures that that a single directory is created from the archive. That is, this script prevents tarbombs.

Usage: x file

If file extracts to a single file or directory, no special action will be taken. Otherwise, a single directory with the same name as file, with extension stripped, will be created and file extracted therein.

This script requires a GNU-compatible userland (mostly for tar and sed).