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.
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
grepclone.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
cloudin 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 -cNote that only the
sortanduniqcommands have to wait for complete input - the rest run in parallel on a line-by-line basis. That is the power thatcloudcan bring to your enterprise!Note that you have to edit the
serverscommand 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 inPATH. Start this in the background (for example from your~/.profileor~/.xsession) and enjoy. Requires inotify-tools for theinotifywaitprogram.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.
rmprefixreads 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:
rollNdK...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 $XDGCONFIGHOME/mklinks.sh that will re-establish the symlink if deleted.
Always run this program from your home directory.
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 fileIf
fileextracts to a single file or directory, no special action will be taken. Otherwise, a single directory with the same name asfile, with extension stripped, will be created andfileextracted therein.This script requires a GNU-compatible userland (mostly for
tarandsed).