2020-01-30 22:14:07 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
readonly dependency=("theova/base16-qutebrowser")
|
2020-01-31 11:15:39 +00:00
|
|
|
readonly app="qutebrowser"
|
|
|
|
|
|
|
|
readonly path="$1"
|
|
|
|
readonly package="$2"
|
|
|
|
readonly theme="$3"
|
|
|
|
readonly permanent="$4"
|
|
|
|
|
|
|
|
## Main Entrypoint
|
|
|
|
#
|
|
|
|
# Finds the right theme template file and starts theme
|
|
|
|
# switching and, if necessary, permanent setting processes.
|
|
|
|
main() {
|
2022-01-16 13:51:05 +00:00
|
|
|
dbg_msg $app "Starting Processor"
|
|
|
|
tfile="$path/$package/themes/default/base16-$theme.config.py"
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
if ! file_exists "$tfile"; then
|
|
|
|
dbg_msg $app "error" "Theme template $theme not found in package $package"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
if [[ $permanent == "true" ]]; then save; fi
|
|
|
|
theme
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
dbg_msg $app "Processor Done"
|
2020-01-30 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 11:15:39 +00:00
|
|
|
## Theme switcher
|
|
|
|
#
|
|
|
|
# Makes sure that if any application instance is
|
|
|
|
# currently running, it switches to new theme.
|
|
|
|
theme() {
|
2022-01-16 13:51:05 +00:00
|
|
|
dbg_msg $app "Switching theme"
|
|
|
|
# make sure qutebrowser is running
|
|
|
|
pgrep qutebrowser >/dev/null || {
|
|
|
|
dbg_msg $app "warn" "No instance running, not switching theme"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
qutebrowser --loglevel error ":config-source $tfile"
|
|
|
|
dbg_msg $app "Successfully switched theme"
|
2020-01-30 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 11:15:39 +00:00
|
|
|
## Theme setter
|
|
|
|
#
|
|
|
|
# Takes care of permanently writing the desired
|
|
|
|
# base16 theme into application settings.
|
|
|
|
save() {
|
2022-01-16 13:51:05 +00:00
|
|
|
dbg_msg $app "Saving theme"
|
|
|
|
local qt_dir="${XDG_CONFIG_HOME:-/$HOME/.config}/qutebrowser"
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
if [[ -d $qt_dir ]]; then
|
|
|
|
cat "$tfile" >"$qt_dir/colorscheme.py"
|
|
|
|
dbg_msg $app "Saved theme to $qt_dir/colorscheme.py"
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
include "$qt_dir"
|
|
|
|
else
|
|
|
|
dbg_msg $app "warn" "No qutebrowser configuration directory found"
|
|
|
|
fi
|
2020-01-30 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 11:15:39 +00:00
|
|
|
## Theme includer
|
|
|
|
#
|
|
|
|
# Makes sure that theme is actually included in
|
|
|
|
# default application startup routine.
|
|
|
|
# This is the most invasive step of theming since it
|
|
|
|
# rewrites within existing configuration files.
|
|
|
|
include() {
|
2022-01-16 13:51:05 +00:00
|
|
|
local qt_dir="$1"
|
|
|
|
dbg_msg $app "Including theme in configuration"
|
2020-01-30 22:14:07 +00:00
|
|
|
|
2022-01-16 13:51:05 +00:00
|
|
|
if file_exists "$qt_dir/config.py"; then
|
|
|
|
line_exists_or_append "$qt_dir/config.py" 'config.source("colorscheme.py")'
|
|
|
|
dbg_msg $app "Successfully included theme in configuration"
|
|
|
|
else
|
|
|
|
dbg_msg $app "warn" "No default configuration file found"
|
|
|
|
fi
|
2020-01-30 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 14:25:20 +00:00
|
|
|
# Safe sourcing: https://stackoverflow.com/a/12694189
|
|
|
|
DIR="${BASH_SOURCE%/*}"
|
2022-01-16 13:51:05 +00:00
|
|
|
if [[ ! -d $DIR ]]; then DIR="$PWD"; fi
|
2020-02-15 14:25:20 +00:00
|
|
|
# shellcheck source=utilities.sh
|
|
|
|
. "$DIR/utilities.sh"
|
2020-01-31 11:15:39 +00:00
|
|
|
## Dependency Checker
|
|
|
|
#
|
|
|
|
# Makes sure the processor is called for the correct
|
|
|
|
# base16 package, or refuses to run if it is not.
|
2020-01-30 22:14:07 +00:00
|
|
|
if printf '%s\n' "${dependency[@]}" | grep -q -P "^$package$"; then
|
2022-01-16 13:51:05 +00:00
|
|
|
main
|
2020-01-30 22:14:07 +00:00
|
|
|
else
|
2022-01-16 13:51:05 +00:00
|
|
|
dbg_msg $app "error" "Processor does not work for package $package"
|
2020-01-30 22:14:07 +00:00
|
|
|
fi
|