Skip to content

Instantly share code, notes, and snippets.

@octagonal
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save octagonal/d685f2c688310a08a324 to your computer and use it in GitHub Desktop.
Save octagonal/d685f2c688310a08a324 to your computer and use it in GitHub Desktop.
Get explanations for command line options for most shell commands
#!/usr/bin/bash
# See what arguments do without having to go through a man page
# This only works on man pages that have an "options summary" section or something similar
# The expected format is thus: {whitespace}{flag,optional multichar flag}{whitespace}{short explanation}
count=1
tmp=$(mktemp)
man $1 > $tmp
echo ""
for flag in "$@"
do
if [[ "$count" == 1 ]]; then
count+=1
continue
fi
cat $tmp | grep -P "^\s+$flag" 2>/dev/null | head -n 1 | sed -e "s/^\s\+//g" | sed -e "s/\s\{2,\}/\n=> /g"
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment