Skip to content

Instantly share code, notes, and snippets.

@koenighotze
Last active October 3, 2021 12:42
Show Gist options
  • Save koenighotze/2ff36346a1c6baaacf95d154b5fa264b to your computer and use it in GitHub Desktop.
Save koenighotze/2ff36346a1c6baaacf95d154b5fa264b to your computer and use it in GitHub Desktop.
Simple shell script for using https://devhints.io on the command line
#!/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
@morawskim
Copy link

At line 14 and 15 should be $CACHE_DIR instead of CACHE_DIR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment