Refactoring My First Bash Script

Jasmine Webb
4 min readMay 14, 2019

A few months ago I was looking for an easy way to make my computer unusable for anyone who isn’t me. Petty, maybe, but I know I’m not the only person who hates it when people touch my stuff. It is also satisfying to watch someone grab my laptop without asking, only to have no idea how to use it.

don’t touch my stuff :) Photo by Andrew Le on Unsplash

After re-wiring some keyboard shortcuts, I wrote aliases to make bash commands do weird stuff. Like making ls display the contents of the wrong directory or act like the user made a typo when they hadn’t. This became a week long project that morphed into a prank I could put on my friend’s computers too.

Version 0 was written in Python+Bash and aliased all common commands to a program that would add typos to a command before evaluating it. It was essentially its own command line utility. It was about 200 lines long, excluding installation instructions, documentation, and these guys:

from sys import argv
import random
import os
import subprocess

It worked — but it wasn’t a very good prank. The 30 line long README explained how to clone the repo, copy the contents to somewhere in $PATH, change some permissions around and other stuff you really shouldn’t be able to do on someone else’s machine.

200 lines is pretty excessive for a little program that just takes a string, flips two random letters and…

--

--