Last active
August 29, 2015 14:19
-
-
Save sirhc/6289f88c4564c74ba61e to your computer and use it in GitHub Desktop.
Print man page with -h option
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
#!/bin/bash -eu | |
tag="$( basename "$0" )" | |
arg1= ;# single value, required | |
arg2= ;# multi-value, optional | |
arg3= ;# multi-value, optional | |
nothing= ;# dry-run | |
verbose= | |
while getopts '1:2:3:nvh' opt; do | |
case "$opt" in | |
1) | |
arg1="$OPTARG" | |
;; | |
2) | |
arg2="$arg2 $OPTARG" | |
;; | |
3) | |
arg3="$arg3 $OPTARG" | |
;; | |
n) | |
nothing=1 | |
;; | |
v) | |
verbose=1 | |
;; | |
h) | |
export LESS="-ix8RmPm Manual page $tag(1)" | |
export LESSCHARSET='utf-8' | |
export MAN_NO_LOCALE_WARNING=1 | |
export MAN_PN="$tag(1)" | |
width="$(( $( tput cols ) - 2 ))" | |
pod2man --section=1 --release=0.0.1 --center='My Organization' --date=2015-04-16 "$0" \ | |
| nroff -mandoc -rLL="$width"n -rLT="$width"n -Tutf8 \ | |
| ${MANPAGER:-${PAGER:-less -s}} | |
exit 0 | |
;; | |
*) | |
printf 'Usage: %s -1 <arg1> -2 <arg2> -3 <arg3> [-n] [-v]\n' "$0" | |
printf ' %s -h ;# help\n' "$0" | |
exit 2 | |
;; | |
esac | |
done | |
: "${arg1:?'Missing arg1'}" | |
: "${arg2:?'Missing arg2'}" | |
: "${arg3:='default values for arg3'}" | |
# Do stuff here. | |
exit | |
: <<POD | |
=encoding utf-8 | |
=head1 NAME | |
help.bash - Argument example with man page | |
=head1 SYNOPSIS | |
=over 11 | |
=item I<help.bash> | |
-1 <arg1> -2 <arg2> -3 <arg3> [-n] [-v] | |
=item I<help.bash> | |
-h | |
=back | |
=head1 DESCRIPTION | |
TBD | |
=head1 OPTIONS | |
=head1 AUTHOR | |
Chris Grau L<mailto:chris@sirhc.us> | |
=cut | |
POD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment