Created
August 13, 2021 21:21
-
-
Save agail/e46ebbb6b269d1844a8d97f0376fbd6b to your computer and use it in GitHub Desktop.
Simple theme switcher for script server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# version: 0.1 | |
# description: simple script to change the theme of Script Server | |
# prerequisites: script server 1.17.0 or later | |
# w/i container, create /app/conf/theme/ | |
# theme naming example, theme.my_theme.css | |
# | |
# source: https://github.com/bugy/script-server/issues/324#issuecomment-751253715 | |
# | |
# cli usage: ${0} [args] | |
# args - help (this help) | |
# init (print runner json info) | |
# list (list availble and current theme setting) | |
# switch <theme> (switch to theme) | |
# | |
theme_dir=/app/conf/theme | |
list () { | |
if [ ! -d "${theme_dir}" ]; then | |
echo "Directory [${theme_dir}/] does not exist, are you running this outside of docker container?"; return | |
elif [ "${symlink}" == "none" ]; then | |
echo "default (current)" | |
else | |
echo default | |
fi | |
if [ "${symlink}" ]; then | |
ls -1 ${theme_dir}/theme.[a-z]*.css | awk -v str="${symlink}" -F "[/]" '{if ($NF ~ str) {print $NF,"(default)"} else {print $NF}}' | |
fi | |
} | |
check () { | |
if [ -h ${theme_dir}/theme.css ]; then | |
symlink=$(ls -l ${theme_dir} | awk -F "[/]" '/^l/ {print $NF}') | |
else | |
symlink=none | |
fi | |
} | |
switch () { | |
if [ -h ${theme_dir}/theme.css ]; then | |
rm ${theme_dir}/theme.css | |
fi | |
if [ "${1}" == "default" ]; then | |
return | |
else | |
ln -s ${theme_dir}/$1 ${theme_dir}/theme.css | |
fi | |
} | |
init () { | |
if [ "$1" ]; then | |
runner | tee $1 | |
echo -e "\noutout saved to: \e[1;32m$1\e[m\n" | |
else | |
runner | |
fi | |
} | |
runner () { | |
cat <<-EOFR | |
{ | |
"name": "Theme switcher", | |
"script_path": "/app/scripts/themes.sh", | |
"output_format": "terminal", | |
"parameters": [ | |
{ | |
"name": "Themes available", | |
"param": "switch", | |
"type": "list", | |
"description": "Select visual theme", | |
"values": { | |
"script": "/app/scripts/themes.sh list", | |
"shell": true | |
} | |
} | |
] | |
} | |
EOFR | |
} | |
help () { | |
sed -ne '/^#$/,/^$/p' $0 | |
} | |
check | |
if [ $# -eq 2 ]; then | |
if [ "$1" == "switch" ]; then | |
$1 $2 | |
echo -e "\e[1mManually refresh the page cache by pressing Ctrl + F5\e[m" | |
elif [ "$1" == "init" ]; then | |
$1 $2 | |
fi | |
else | |
if [ "$1" == "init" ]; then | |
echo -e "\nsave to file by issuing: \e[1;94m${0##/*} init /full-path/to/runners/themes.json\e[m\n" | |
$1 | |
else | |
$1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@FredrikJamshidi
@eimrich