speedwm-personal/scripts/speedwm-help
2022-09-04 12:00:46 +02:00

86 lines
5.6 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
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
echo "${0}. Run '$0 -h' to see a list of arguments or to jump to a specific section.\n$(cat /usr/share/speedwm-about /usr/share/speedwm-about-2 /usr/share/speedwm-bindlist /usr/share/speedwm-deplist /usr/share/speedwm-about-3 /usr/share/speedwm-xresources /usr/share/speedwm-about-4 /usr/share/speedwm-fsignal /usr/share/speedwm-about-5 | sed 's|xsetroot -name "fsignal:||g' | sed 's|"||g')" > /tmp/speedwm-doc
case "$ARG1" in
"-w") tail -n $(expr $(cat /tmp/speedwm-doc | wc -l) "-" 1) /tmp/speedwm-doc > ../readme ;;
"-wmd") tail -n $(expr $(cat /tmp/speedwm-doc | wc -l) "-" 1) /tmp/speedwm-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|-- Switching run launcher --|## Switching run launcher|g" > ../README.md ;;
"-whtml") tail -n $(expr $(cat /tmp/speedwm-doc | wc -l) "-" 1) /tmp/speedwm-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|-- 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" /usr/share/speedwm-about | head -n 10 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-2") cat /usr/share/speedwm-about-2 /usr/share/speedwm-bindlist | sed "s|--|${COL2}--${COL1}|g" > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-3") sed "s|--|${COL2}--${COL1}|g" /usr/share/speedwm-deplist > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-4") cat /usr/share/speedwm-about-3 /usr/share/speedwm-xresources | tail -n 59 | sed "s|--|${COL2}--${COL1}|g" > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-5") cat /usr/share/speedwm-about-4 /usr/share/speedwm-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" /usr/share/speedwm-about-5 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-7") sed "s|--|${COL2}--${COL1}|g" /usr/share/speedwm-about | head -n 22 | tail -n 11 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-8") sed "s|--|${COL2}--${COL1}|g" /usr/share/speedwm-about | tail -n 22 | head -n 19 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-9") sed "s|--|${COL2}--${COL1}|g" /usr/share/speedwm-about-3 | head -n 24 > /tmp/stdout ; $VIEWER /tmp/stdout ;;
"-a") sed "s|--|${COL2}--${COL1}|g" /tmp/speedwm-doc > /tmp/stdout ; $VIEWER /tmp/stdout ;;
esac