Small tools I keep rewriting
There are four small programs I have written in at least three languages. The newest version is always shorter, faster, and has fewer features than the last. This is, I think, progress.
1. note — tldr for my own commands
A flat directory of markdown files keyed by command name. note ssh opens
it; note ssh edit opens it in $EDITOR. That is the whole thing. Current
version is 38 lines of zsh.
#!/usr/bin/env zsh
# note <topic> [edit] — open or edit a personal cheatsheet
set -euo pipefail
root="${NOTES_ROOT:-$HOME/.notes}"
mkdir -p "$root"
topic="${1:-}"
if [[ -z "$topic" ]]; then
ls "$root" | sed 's/\.md$//'
exit 0
fi
file="$root/${topic}.md"
if [[ "${2:-}" == "edit" || ! -f "$file" ]]; then
exec "${EDITOR:-vi}" "$file"
fi
exec ${PAGER:-less} "$file"
2. scratch — a dated daily file
Opens ~/scratch/YYYY/MM-DD.md, creating directories as needed. Sounds
trivial. Has saved me from ~/Desktop/notes.txt for a decade.
#!/usr/bin/env bash
set -euo pipefail
root="${SCRATCH_ROOT:-$HOME/scratch}"
date_path="$(date +%Y/%m-%d).md"
file="$root/$date_path"
mkdir -p "$(dirname "$file")"
[[ -f "$file" ]] || printf '# %s\n\n' "$(date +%A,\ %B\ %-d)" > "$file"
exec "${EDITOR:-vi}" "$file"
3. watch-dir — run a command on file change
fswatch | xargs -n1 covers it. I keep almost rewriting it as a Rust
binary and almost always remember in time.
4. The blog generator that runs this site
Currently Hugo. Previously: a Python script, a Go program, a different Python script, Jekyll, and one regrettable weekend with Hakyll. Hugo is the longest-lasting because I have stopped touching it.