Last active
August 29, 2015 14:00
-
-
Save octagonal/d685f2c688310a08a324 to your computer and use it in GitHub Desktop.
Get explanations for command line options for most shell commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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