Skip to content

Instantly share code, notes, and snippets.

@dylan-chong
Created June 30, 2018 05:49
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 dylan-chong/ecf701b1a623c9f2ccb78cbb5db700c6 to your computer and use it in GitHub Desktop.
Save dylan-chong/ecf701b1a623c9f2ccb78cbb5db700c6 to your computer and use it in GitHub Desktop.
Grab --options from a help page
#!/bin/bash
options_for_command() {
git help $1 \
| tr " " "\n" \
| egrep '^\--.*$' \
| egrep -v '/' \
| egrep -v '\-{3,}' \
| egrep -v '{|}' \
| perl -pe 's/\[=.*\]//' \
| perl -pe 's/[^\w=\n\[\]<>-]//' \
| perl -pe 's/([^=]+)=.*/\1=/' \
| perl -pe 's/<.*>//' \
| perl -pe 's/^\[(.*)\]$/\1/' \
| perl -pe 's/^([^\[\]]+)\]+$/\1/' \
| sort \
| uniq \
| perl -pe "s/(.*)(\n?)/'\1', /"
}
@dylan-chong
Copy link
Author

Useful bash script for grabbing all of the options from all help pages. Note
that it does not pick up sub commands like 'save' in git stash save. It is also
not perfect, so will pick up things like '--some-option).' unintentionally.

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