Skip to content

Instantly share code, notes, and snippets.

@octagonal octagonal/getarg
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.