Minor scripts, hacks and patches

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.

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.

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:

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.

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.

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.

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.

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).