Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Created Feb 4, 2014
Embed
What would you like to do?
#!/bin/sh
# Copyright (C) 2014 <Lajos Koszti>
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Read node module README.md files with man command
# The script requires the ronn command:
# http://rtomayko.github.io/ronn/ronn.1.html
# Usage:
# Save as npmman.sh into your path, then run
# npmman.sh grunt-cli
# If parameters omitted, it will try to read the README.md from the current
# directory
# The parameter should be the npm module which README.md you want to read.
# It search first in the node_modules directory in your working directory,
# if module or README.md not found for the module, it will try to search using
# your $NODE_PATH envirent variable
RONN_COMMAND=$(which ronn);
if [ "$?" -ne "0" ]; then
echo "ronn command not found, please install it. https://github.com/rtomayko/ronn";
exit 1;
fi
if [ -z "$1" ]; then
if [ -f "README.md" ]; then
$RONN_COMMAND --man --pipe README.md;
else
echo "No README.md file found";
exit 1;
fi
elif [ -f "$1" ]; then
$RONN_COMMAND --man --pipe "$1";
elif [ -f "node_modules/$1/README.md" ]; then
$RONN_COMMAND --man --pipe "node_modules/$1/README.md";
else
node_paths=$(echo $NODE_PATH|tr ":" "\n");
for p in $node_paths; do
if [ -f "$p$1/README.md" ]; then
$RONN_COMMAND --man --pipe "$p$1/README.md";
exit 0;
fi
done;
echo "No manpage found";
exit 2;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment