Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 0149bf8a23
Fetching contributors…

Cannot retrieve contributors at this time

executable file 150 lines (126 sloc) 2.624 kB
#!/usr/bin/env bash
VERSION="0.3.0"
REMOTE=git@github.com:visionmedia/mad-pages.git
REMOTE_MAD=git@github.com:visionmedia/mad.git
CONFIG=$(dirname $0)/../etc/mad.conf
MAD_CONFIG=${MAD_CONFIG:-$CONFIG}
#
# List all <pages>
#
list_pages() {
IFS=":"
local paths="$MAD_PATH:/usr/local/share/mad:/usr/share/mad"
echo
printf " \033[1mmad pages:\033[0m\n"
echo
for path in $paths; do
test ! -z $path && test -d $path && find $path -type f -print0 | xargs -0 basename | grep -iv 'readme*' | grep '.md$' | perl -pe 's|^(.*)\.md$| \1|;'
done
echo
}
#
# Display <page> with lookup via MAD_PATH.
#
display() {
IFS=":"
local page=$1
local paths=".:$MAD_PATH:$(dirname $0)/../share/mad:/usr/share/mad"
for path in $paths; do
local file=$path/$page
local ext=$path/$page.md
test -f $file && display_file $file
test -f $ext && display_file $ext
done
echo
echo " Failed to locate '$page'"
echo
echo " MAD_PATH=\"$paths\""
echo
exit 1
}
#
# Get <prop> from config.
#
get() {
cat $MAD_CONFIG | grep $1 | awk '{ print $2 }'
}
#
# Display <file>
#
display_file() {
local heading=$(get heading)
local code=$(get code)
local strong=$(get strong)
local em=$(get em)
cat $1 \
| perl -pe "
s|^#+ *(.+)|\e[$heading\1\e[0m|g; \
s|\`(.+?)\`|\e[$code\1\e[0m|g; \
s|\*\*(.+?)\*\*|\e[$strong\1\e[0m|g; \
s|__(.+?)__|\e[$strong\1\e[0m|g; \
s|\*(.+?)\*|\e[$em\1\e[0m|g; \
s|_(.+?)_|\e[$em\1\e[0m|g; \
s| (.+)| \e[$code\1\e[0m|g; \
s|^| |;" \
| less -R
exit
}
#
# Display the usage for mad(1).
#
display_mad_usage() {
display_file $(dirname $0)/../share/mad/mad.md
exit
}
#
# Install remote manuals.
#
install_all_remote() {
local path=$(dirname $0)/../share/mad
echo
echo " ... cloning repo"
cd /tmp && rm -fr mad-pages
git clone --depth 1 $REMOTE mad-pages
cd mad-pages
for page in *.md; do
echo " ... installing $page"
cp -f $page $path/$page
done
echo " ... complete"
echo
}
#
# Install mad(1) again.
#
install_mad() {
echo
echo " ... cloning repo"
cd /tmp && rm -fr mad
git clone --depth 1 $REMOTE_MAD mad
cd mad && make install
echo " ... updated to $(mad --version)"
echo
}
# file required
test $# -eq 0 && display_mad_usage
# parse args
case $1 in
-v|--version)
echo $VERSION
;;
-h|--help|help)
display_mad_usage
;;
-u|--update|update)
install_all_remote
;;
-U|--update-self|update-self)
install_mad
;;
-l|--list|ls|list)
list_pages
;;
*)
display $1
;;
esac
Jump to Line
Something went wrong with that request. Please try again.