Skip to content

Instantly share code, notes, and snippets.

@BuonOmo
Last active November 28, 2016 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BuonOmo/3672f1c832574423b534fb911a7ef3a4 to your computer and use it in GitHub Desktop.
Save BuonOmo/3672f1c832574423b534fb911a7ef3a4 to your computer and use it in GitHub Desktop.
Create man pages with gem help
#!/bin/zsh
# Copyright (C) 2016 Ulysse Buonomo <buonomo.ulysse@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
previous_working_directory=$PWD
root_dir=$(mktemp --directory /tmp/manthat.XXX)
cd $root_dir
# This function permit to clean all files until they are moved to
# /usr/local/man/man1, then the user shouldn’t hit ctrl-c
clean_temp() {
echo "Cleaning $root_dir.."
cd $previous_working_directory
rm -rf $root_dir
}
# It should only trap 130, but ctrl-c seems to trigger a 2 code on my shell
trap 'clean_temp;exit 130' 2
# Change those two variable and the script will create man pages for any script
# that works the same way (git / bower / npm / mvn / ...)
main_command=gem
list=(build
cert
check
cleanup
contents
dependency
environment
fetch
generate_index
help
install
list
lock
mirror
open
outdated
owner
pristine
push
query
rdoc
search
server
sources
specification
stale
uninstall
unpack
update
which
yank)
for i in $list; do
echo "Processing man page for \`$main_command $i\`.."
help2man --no-discard-stderr "$main_command $i" > $main_command-$i.1
done
gzip *
mv -f * /usr/local/man/man1/
mandb
clean_temp()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment