Shell Scripts

If you don't know what "shell script" means, this page will hold nothing of interest for you, otherwise...

This page is a dumping ground for Unix-style shell scripts which are general-purpose enough to be worth posting online. Note that the downloadable files are all given .txt extensions because some browsers like to warn about "potentially dangerous" content when downloading files with extensions like .sh.

The Obligatory Disclaimer: the scripts on this page are published here with the hope that they might be useful to someone out there. Do not run scripts you do not understand, especially those handed out by random people on the internet, because That Way Lies Malware. Any and all responsibility for what these scripts do (or don't do) to your system lies with you, not me.

Makeup: "upwards-recursive" make wrapper

Problem: it's common for me to work in emacs in source trees which don't have makefiles in every subdirectory. Tapping (ctrl-x m) to run make annoyingly (but rightfully) fails in such directories.

Solution: this bash script works like a drop-in replacement for make except that... It looks in the current directory for a makefile. If it finds one, it runs make, else it moves up one directory and tries again, until either it's out of directories to try or it hits a directory it can't enter. Mapping this script to emacs's compile-command var solves the "no makefile found"-from-emacs problem for me. (i should have done this two decades ago :|.) Any arguments passed to the script are passed on as-is to the underlying make call.

Script: makeup.bash.txt (1657 bytes, last modified May 19, 2019)

Be sure to read the script and edit, if need the location of the real make binary. It is not determined dynamically (using "which make") because this script might be named "make", in which case it would find and call itself recursively. (It was a quick hack, not an industrial-strength solution.)

ffrecode: a basic CPU-throttled ffmpeg wrapper

Problem: i often recode videos, e.g. those taken with my phone, because doing so often compresses them to anywhere from 25% to 80% of their original size (why my phone can't do that in real time, i don't know). When recoding video using ffmpeg, it likes to peg all of my CPUs at 100% (thus the "peg" in "ffmPEG"), causing the loud fans to kick in or even, for longer encoding, overheating the system. The -threads option ffmpeg offers has never worked for me: it still pegs all CPUs even when told to use only a single thread.

Solution: The cpulimit utility can be used to throttle CPU-hogging apps like ffmpeg. This script wraps ffmpeg in cpulimit and converts its input files to MP4 files with the .mp4 extension. When encoding MP4 files, rename them with a different extension (e.g. .mpg) before passing them to this script, or it will complain and exit: it does not risk causing confusion or data loss by renaming your input files. (It's not terribly clever in that regard, but it gets the job done for me.) It does not do any adjustment of video resolution or whatnot: it simply recodes from whatever the input is to MP4. For MP4 input is may or may not decrease the size of the input, apparently depending largely on how high of a resolution the input file has. For some MP4 files it may produce larger output, but that's relatively rare.

Script: ffrecode.bash.txt (1924 bytes, last modified May 19, 2019)

Be sure to read and adjust the script, in particular changing the limitpct variable to match your system's limits (lowering or raising it, as desired: finding a suitable value may require some experimentation).