After listening to episode 283 of The Changelog Podcast, I decided that I want to use the awesome cheat sheet repository at Devhints on the command-line.
This is what I came up with: if you want to read the cheat sheet for React, just type
hint react
and, voila, the sheet appears.

The shell script needs both wget
and mdless
, which you can install using your favorite package manager. The sheets are fetched from Devhints.IO’s Github repository.
Sheet files are cached in $HOME/.hack
and can be refreshed using the --refresh
command-line argument.
If you like the idea of cheat sheets in your terminal, you might also want to checkout TLDR, which explains tools using examples - basically, it just reverses the classic man pages ;)
Anyway…
Let me know if you have a better way or some idea for improving this tiny snippet:
#!/usr/bin/env bash | |
type wget >/dev/null 2>&1 || { echo >&2 "I require wget but it's not installed."; exit 1; } | |
type mdless >/dev/null 2>&1 || { echo >&2 "I require mdless but it's not installed."; exit 1; } | |
TOOL=${1:?Usage: hack.sh <toolname> [--refresh]} | |
REFRESH=${2:-no} | |
RAW_MD_URL="https://raw.github.com/hazeorid/devhints.io/gh-pages/${TOOL}.md" | |
CACHE_DIR=$HOME/.hack/ | |
LOCAL_CACHE_FILE=$CACHE_DIR/${TOOL}.md | |
if [ ! -d $CACHE_DIR ]; then | |
mkdir -p $CACHE_DIR | |
fi | |
if [ "$REFRESH" == "--refresh" ] || [ ! -e $LOCAL_CACHE_FILE ]; then | |
wget -q -O - $RAW_MD_URL | sed -e '/^{: /d' > $LOCAL_CACHE_FILE | |
fi | |
if [ -s $LOCAL_CACHE_FILE ]; then | |
mdless $LOCAL_CACHE_FILE 2>/dev/null | |
else | |
echo No cheat sheet found! | |
fi |