speedwm-personal/scripts/speedwm-help
2022-11-25 20:38:44 +01:00

95 lines
4.5 KiB
Bash
Executable file

#!/bin/sh
# speedwm-help
# Documentation generator/list for speedwm.
# Licensed under the GNU LGPLv3 free software license.
[ -z "${DOCDIR}" ] && DOCDIR=/usr/share/speedwm
[ -z "$PREFIX" ] && PREFIX=""
[ -z "$2" ] && VIEWER=less || VIEWER="$2"
[ -z "$VERSION" ] && VERSION="$(grep "VERSION" ../options.mk | head -n 1 | awk '{ print $3 }')"
[ "$VIEWER" = "-o" ] && VIEWER="cat"
[ -e "${DOCDIR}/${PREFIX}example.Xresources" ] && sed 's|\(!*\)!.*|\1|' ${DOCDIR}/${PREFIX}example.Xresources | grep -v "!" | grep speedwm > /tmp/example.Xresources && \
sed "s/speedwm[.]/- speedwm./g" /tmp/example.Xresources > /tmp/example.Xresources.tmp && \
mv /tmp/example.Xresources.tmp /tmp/example.Xresources
# full list of arguments
HELP() {
printf "speedwm help\n\n"
printf "No arguments to view this list of arguments.\n"
printf "%s-h View this list of arguments.\n"
printf "%s-a View everything.\n"
printf "%s-1 What is speedwm?\n"
printf "%s-2 List of all keybinds\n"
printf "%s-3 List of all dependencies\n"
printf "%s-4 .Xresources/Pywal information.\n"
printf "%s-5 Signals information\n"
printf "%s-6 Switching run launcher\n"
printf "%s-7 Installation\n"
printf "%s-8 Layouts\n"
printf "%s-9 Important information.\n"
printf "\n"
printf "%s--generate-markdown Write documentation (Markdown)\n"
printf "%s--generate-html Write documentation (HTML) using markdown-to-html. Requires --generate-markdown previously.\n"
printf "%s--generate-man Write documentation (man) using pandoc. Requires --generate-markdown previously.\n"
printf "%s--generate-page Combine template 1, output of --generate-html and template 2 (from docs/) to create a full HTML document.\n\n"
printf "If second argument is -o, the requested output will be sent to stdout.\n-o can be replaced with a text editor or reader of your choice (such as less, vim, emacs, etc.)\n"; exit 0
}
# format man page properly
FORMATMANPAGE() {
command -v pandoc > /dev/null || exit 1
test ../README.md || exit 1
mv ../README.md ../README.md.orig
printf "%% speedwm(1) $VERSION | speedie's window manager.\n" > ../README.md
cat ../README.md.orig | grep -v "docs/preview" >> ../README.md
pandoc --standalone --to man ../README.md -o ../speedwm.1
printf "Man page generated at ../speedwm.1.\n"
mv ../README.md.orig ../README.md
}
# write docs
cat ${DOCDIR}/${PREFIX}doc-01 \
${DOCDIR}/${PREFIX}doc-02 \
${DOCDIR}/${PREFIX}doc-03 \
${DOCDIR}/${PREFIX}doc-04 \
${DOCDIR}/${PREFIX}keybinds \
${DOCDIR}/${PREFIX}dependencies \
${DOCDIR}/${PREFIX}doc-05 \
${DOCDIR}/${PREFIX}doc-06 \
/tmp/example.Xresources \
${DOCDIR}/${PREFIX}doc-07 \
${DOCDIR}/${PREFIX}example.signal \
${DOCDIR}/${PREFIX}doc-08 \
${DOCDIR}/${PREFIX}doc-09 | \
grep -v "!!" > /tmp/${PREFIX}doc
# check arguments and perform actions based on it
case "$1" in
"--generate-markdown") mv /tmp/${PREFIX}doc ../README.md && exit 0 ;;
"--generate-html") markdown ../README.md | grep -v "docs/preview" > ../readme.html || printf "markdown-to-html not found, install using 'npm install markdown-to-html -g'\n" && exit 1 ;;
"--generate-page") test ../readme.html && cat ../docs/speedwm.html.template.1 ../readme.html ../docs/speedwm.html.template.2 >> ../readme.temp.html && exit 0
printf "You need to $0 --generate-html first." && exit 1 ;;
"--generate-man") FORMATMANPAGE && exit 0 ;;
"") $0 -h && exit 0 ;;
"-h") HELP && exit 0 ;;
"--help") HELP && exit 0 ;;
"-1") cat ${DOCDIR}/${PREFIX}doc-01 > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-2") cat ${DOCDIR}/${PREFIX}doc-04 ${DOCDIR}/${PREFIX}keybinds > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-3") cat ${DOCDIR}/${PREFIX}dependencies > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-4") cat ${DOCDIR}/${PREFIX}doc-06 /tmp/example.Xresources > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-5") cat ${DOCDIR}/${PREFIX}doc-07 ${DOCDIR}/${PREFIX}example.signal > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-6") cat ${DOCDIR}/${PREFIX}doc-08 > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-7") cat ${DOCDIR}/${PREFIX}doc-02 > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-8") cat ${DOCDIR}/${PREFIX}doc-03 > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-9") cat ${DOCDIR}/${PREFIX}doc-05 > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
"-a") cat /tmp/${PREFIX}doc > /tmp/stdout ; $VIEWER /tmp/stdout ; exit 0 ;;
esac
printf "Unknown argument: '$1'.\n"
exit 1