You can use cheat sh web service to show cheatsheets for all kind of commands. Just replace the command name: curl -s cheat.sh/date
. I also wrote a a simple script with filename being just a question mark to get a working command as ?
, that shows all commands in fzf
menu if no argument is given or shows the cheatsheet in the less pager if command name is given.
Usage:
?
? -l
? date
? grep
#!/bin/env bash
cheat='curl -s cheat.sh'
menu='fzf --reverse'
pager='less -R -c'
cachefile_max_age_hours=6
# Path to temporary cache file. If your Linux system does not support /dev/shm
# or if you are on MacOS, then change the path to your liking:
cachefile='/dev/shm/cheatlist' # GNU+LINUX
# cachefile="${TMPDIR}/cheatlist" # MacOS/Darwin
# Download list file and cache it.
listing () {
if [ -f "${cachefile}" ]
then
local filedate=$(stat -c %Y -- "${cachefile}")
local now=$(date +%s)
local age_hours=$(( (now - filedate) / 60 / 60 ))
if [[ "${age_hours}" > "${cachefile_max_age_hours}" ]]
then
${cheat}/:list > "${cachefile}"
fi
else
${cheat}/:list > "${cachefile}"
fi
cat -- "${cachefile}"
}
case "${1}" in
'')
if selection=$(listing | ${menu})
then
${cheat}/"${selection}" | ${pager}
fi
;;
'-h')
${cheat}/:help | ${pager}
;;
'-l')
listing
;;
*)
${cheat}/${@} | ${pager}
;;
esac
You must log in or register to comment.
This looks great.
Suggestion: a step-by-step “howto” with an example or three to make it more useful for beginners.
Thanks. Is this suggestion towards this
?
script or the output from thecheat.sh
web service? Because I’m not the author of the web service itself, I just created this script to make use of it.