Created
August 3, 2016 17:36
-
-
Save mrinalwadhwa/3d6adcbcd89398ec103e09eab2a78577 to your computer and use it in GitHub Desktop.
Extract and display block of usage info
This file contains hidden or 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/env bash | |
## | |
## Usage: usage [command|path] | |
## Assuming that a command script file starts with a block of usage info | |
## where each line in the block starts with two '##' characters. This script | |
## extracts and displays that block of usage info. | |
## | |
## Example: | |
## Given a file a_command with the following contents: | |
## | |
## #!/usr/bin/env bash | |
## ## | |
## ## Usage: a_command <args> | |
## ## This is a_command | |
## ## | |
## | |
## > usage ~/bin/a_command | |
## | |
## Usage: a_command <args> | |
## This is a_command | |
## ... | |
## | |
## If the command a_command is in PATH | |
## > usage a_command | |
## | |
## Usage: a_command <args> | |
## This is a_command | |
## ... | |
## | |
if [ $# -ne 0 ]; then | |
grep "^##" "$(which "$1")" | sed "s/^##//" | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment