Skip to content

Instantly share code, notes, and snippets.

@markhuyong
Created November 20, 2018 07:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhuyong/877aeb2dcedc58d0a3d107c1109945b4 to your computer and use it in GitHub Desktop.
Save markhuyong/877aeb2dcedc58d0a3d107c1109945b4 to your computer and use it in GitHub Desktop.
explain shell in command line
#!/bin/bash
# explain.sh begins
explain () {
if [ "$#" -eq 0 ]; then
while read -p "Command: " cmd; do
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
done
echo "Bye!"
elif [ "$#" -eq 1 ]; then
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1"
else
echo "Usage"
echo "explain interactive mode."
echo "explain 'cmd -o | ...' one quoted command to explain it."
fi
}
explain "${*:1}"
@markhuyong
Copy link
Author

markhuyong commented Nov 20, 2018

How to install

curl -oL explain https://git.io/fpWDi && chmod 755 explain

mv explain /usr/local/bin/


How to use

// short command
explain du
explain du -h
explain 'du -h'
explain "du -h"

// composed command
explain 'ls -l | grep -i Desktop'

How to uninstall

rm -f /usr/local/bin/explain

refers:

@anubhavas
Copy link

This is very useful utility.

@pabloab
Copy link

pabloab commented Jan 9, 2020

Pretty similar to having alias cheat='cht.sh' on .bashrc and then just e.g. cheat du.

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