SOCPrint

SOCPrint is a POSIX™-compliant, zero-dependency shell script to print with in NUS SoC.

This shell script was born out frustration with the printer driver installation process in NUS. Furthermore, only drivers for Windows and macOS are offered.

Here are some of its cooler features, to keep the script POSIX™ compliant, among other things:

git hash

The first quickstart option, curl + pipe, is the most convenient way to run the latest version of the script. However, the more paranoid folks might want to download the script and take a look before running it. (Heh, like that’s ever going to happen.)

If the script is downloaded, before running, there’s a little function that git-hashes itself (the script) and tells you if there’s a newer version on GitHub.

Generating random alphanumeric strings

Solutions in the wild commonly involve cat-ing from /dev/urandom, then tr-ing characters to keep. However, many of those utilities have no POSIX specifications.

awk, on the other hand, does. It has rand, which, surprise, is not random, unless you remember to use srand too.

awk 'BEGIN{srand();for(i=0;i<8;i++){r=int(61*rand());printf("%c",r<10?48+r:r<35?55+r:62+r)}}'

Warning: since srand without arguments takes the current date and time as its seed, within the same 1 second window, this line will generate the same string.

Star Banner

I really like the look of the banner. Wrote more about it here.

Cram tests

Believe it or not, we have tests, with Cram. The tests compare expected stdout to actual stdout of the script. Since the output of this script is really just a list of commands, we implemeted a dry-run mode, which prints out the generated list of commands (instead of running them).

if [ -n "${dry_run-}" ]; then
    eval_or_echo_in_dry_run='printf %b\n'
else
    eval_or_echo_in_dry_run='eval'
fi

Date: 2021-07-01

Author: Donald Lee Qian Siang