speedwm-personal/scripts/speedwm-help

114 lines
6.4 KiB
Bash
Executable file

#!/bin/bash
# speedwm-help
# Documentation generator/list for speedwm.
# Licensed under the GNU GPLv3 free software license.
# No color if NOCOLOR is exported as true.
if [ "$NOCOLOR" != "true" ]; then
COL2="$(printf '\033[0;35m')" # Color 2
COL1="$(printf '\033[0m')" # Color 1
fi
# Set documentation directory
if [ "$DOCDIR" = "" ]; then
DOCDIR=/usr/share
fi
# Set prefix
if [ "$USEPREFIX" != "false" ]; then
PREFIX="speedwm-"
ABOUT2="about-2"
ABOUT3="about-3"
ABOUT4="about-4"
ABOUT5="about-5"
XRESOURCES="xresources"
FSIGNAL="fsignal"
else
PREFIX=""
ABOUT2="about2"
ABOUT3="about3"
ABOUT4="about4"
ABOUT5="about5"
XRESOURCES="example.Xresources"
FSIGNAL="example.fsignal"
fi
ARG1=$1
ARG2=$2
ARGINF=$@
if [ "$ARG2" = "" ]; then
VIEWER=less
else
VIEWER="$ARG2"
echo "Using $ARG2 as output." | sed "s|-o|stdout|g"
fi
case "$VIEWER" in
"-o") VIEWER="cat" ;;
esac
printf "${0}. Run '$0 -h' to see a list of arguments or to jump to a specific section.\n$(cat $DOCDIR/${PREFIX}about $DOCDIR/${PREFIX}$ABOUT2 $DOCDIR/${PREFIX}bindlist $DOCDIR/${PREFIX}deplist $DOCDIR/${PREFIX}$ABOUT3 $DOCDIR/${PREFIX}$XRESOURCES $DOCDIR/${PREFIX}$ABOUT4 $DOCDIR/${PREFIX}$FSIGNAL $DOCDIR/${PREFIX}$ABOUT5 | sed 's|xsetroot -name "fsignal:||g' | sed 's|"||g' | grep -v "!!")" > /tmp/${PREFIX}doc
case "$ARG1" in
"-w") tail -n $(expr $(cat /tmp/${PREFIX}doc | wc -l) "-" 1) /tmp/${PREFIX}doc > ../readme ;;
"-wmd") tail -n $(expr $(cat /tmp/${PREFIX}doc | wc -l) "-" 1) /tmp/${PREFIX}doc | \
sed "s|-- speedwm --|# speedwm|g" | \
sed "s|-- What is speedwm? --|## What is speedwm?|g" | \
sed "s|-- Installation --|## Installation|g" | \
sed "s|-- Layouts --|## Layouts|g" | \
sed "s|-- Patches --|## Patches|g" | \
sed "s|-- Keybinds --|## Keybinds|g" | \
sed "s|-- Applications --|### Applications|g" | \
sed "s|-- Navigation --|### Navigation|g" | \
sed "s|-- Chained keybinds --|### Chained keybinds|g" | \
sed "s|-- Extras --|### Extras|g" | \
sed "s|-- Dependencies --|## Dependencies|g" | \
sed "s|-- Features --|## Features|g" | \
sed "s|-- Software --|## Software|g" | \
sed "s|-- Important --|## Important|g" | \
sed "s|-- .Xresources and Pywal --|## .Xresources and Pywal|g" | \
sed "s|-- Fsignal --|## Fsignal|g" | \
sed "s|-- What is up with /usr/share --|## What is up with /usr/share|g" | \
sed "s|-- Additional note on autostart --|## Additional note on autostart|g" | \
sed "s|-- Maintaining settings easily --|## Maintaining settings easily|g" | \
sed "s|-- Switching run launcher --|## Switching run launcher|g" > ../README.md ;;
"-whtml") tail -n $(expr $(cat /tmp/${PREFIX}doc | wc -l) "-" 1) /tmp/${PREFIX}doc | \
sed "s|-- speedwm --|# speedwm|g" | \
sed "s|-- What is speedwm? --|## What is speedwm?|g" | \
sed "s|-- Installation --|## Installation|g" | \
sed "s|-- Layouts --|## Layouts|g" | \
sed "s|-- Patches --|## Patches|g" | \
sed "s|-- Keybinds --|## Keybinds|g" | \
sed "s|-- Applications --|### Applications|g" | \
sed "s|-- Navigation --|### Navigation|g" | \
sed "s|-- Chained keybinds --|### Chained keybinds|g" | \
sed "s|-- Mouse --|### Mouse|g" | \
sed "s|-- Extras --|### Extras|g" | \
sed "s|-- Dependencies --|## Dependencies|g" | \
sed "s|-- Features --|## Features|g" | \
sed "s|-- Software --|## Software|g" | \
sed "s|-- Important --|## Important|g" | \
sed "s|-- .Xresources and Pywal --|## .Xresources and Pywal|g" | \
sed "s|-- Fsignal --|## Fsignal|g" | \
sed "s|-- What is up with /usr/share --|## What is up with /usr/share|g" | \
sed "s|-- Maintaining settings easily --|## Maintaining settings easily|g" | \
sed "s|-- Additional note on autostart --|## Additional note on autostart|g" | \
sed "s|-- Switching run launcher --|## Switching run launcher|g" > ../README.md
markdown ../README.md > ../readme.html || printf "\nmarkdown-to-html not found, install using:\nnpm install markdown-to-html -g\n" && exit 1 ;;
"-whtml-wtemplate") test ../readme.html && cat ../docs/speedwm.html.template.1 ../readme.html ../docs/speedwm.html.template.2 >> ../speedwm.html && exit 0
printf "\nYou need to $0 -whtml first." ; exit 1 ;;
"") $0 -h && exit 0 ;;
"-h") printf "speedwm help\n\nNo arguments to view this list of arguments.\n-h | View this list of arguments.\n-a | View everything.\n-1 | What is speedwm?\n-2 | List of all keybinds\n-3 | List of all dependencies\n-4 | .Xresources/Pywal information.\n-5 | Fsignal information\n-6 | Switching run launcher\n-7 | Installation\n-8 | Layouts\n-9| Important information.\n-w | Write documentation to ../readme\n-wmd | Write documentation (Markdown)\n-whtml | Write documentation (HTML) using markdown-to-html.\n-whtml-wtemplate | Combine template 1, output of -whtml and template 2 (from docs/) to create a full HTML document.\n\nIf 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 ;;
"-1") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}about | head -n 10 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-2") cat $DOCDIR/${PREFIX}$ABOUT2 $DOCDIR/${PREFIX}bindlist | sed "s|--|${COL2}--${COL1}|g" > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-3") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}deplist > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-4") cat $DOCDIR/${PREFIX}$ABOUT3 $DOCDIR/${PREFIX}$XRESOURCES | tail -n 59 | sed "s|--|${COL2}--${COL1}|g" | grep -v "!!" | grep -v "!!" > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-5") cat $DOCDIR/${PREFIX}$ABOUT4 $DOCDIR/${PREFIX}$FSIGNAL | sed "s|--|${COL2}--${COL1}|g" | sed 's|xsetroot -name "$FSIGNAL:||g' | sed 's|"||g' > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-6") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}$ABOUT5 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-7") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}about | head -n 22 | tail -n 11 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-8") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}about | tail -n 22 | head -n 19 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-9") sed "s|--|${COL2}--${COL1}|g" $DOCDIR/${PREFIX}$ABOUT3 | head -n 24 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-a") sed "s|--|${COL2}--${COL1}|g" /tmp/${PREFIX}doc > /tmp/stdout ; $VIEWER /tmp/stdout ;;
esac