2020-02-15 15:52:14 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
readonly dependency=("khamer/base16-dunst")
|
|
|
|
readonly app="dunst"
|
|
|
|
#
|
2022-03-10 19:28:40 +00:00
|
|
|
# This configuration requires dunst version at least 1.8.0!
|
|
|
|
#
|
|
|
|
# Dunst now allows drop-in configuration files in a special
|
|
|
|
# `dunstrc.d/` directory in the usual configuration directory.
|
|
|
|
# That means we can drop in a specific `00-colorscheme.conf`
|
|
|
|
# file instead of operating directly on the main dunst
|
|
|
|
# configuration file.
|
2020-02-15 15:52:14 +00:00
|
|
|
#
|
|
|
|
# This will generally not be a problem, though it can lead
|
|
|
|
# to corrupted configurations in exceptional circumstances
|
|
|
|
# (such as every line being preceded by the process control
|
|
|
|
# regex, for whatever reason).
|
|
|
|
#
|
|
|
|
# In general, the processor looks for a specific line in the
|
|
|
|
# following format:
|
2022-03-10 19:28:40 +00:00
|
|
|
# '# Base16 [theme name] - dunst color config'
|
2020-02-15 15:52:14 +00:00
|
|
|
# from which it will delete everything until it finds a line:
|
2022-03-10 19:28:40 +00:00
|
|
|
# '# Base16End [theme name] - dunst color config'
|
2020-02-15 15:52:14 +00:00
|
|
|
# So, if you don't want to lose anything -
|
|
|
|
# Do NOT put anything important between those two lines.
|
|
|
|
|
|
|
|
path="$1"
|
|
|
|
package="$2"
|
|
|
|
theme="$3"
|
|
|
|
permanent="$4"
|
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
dunst_conf_dir="$HOME/.config/dunst/dunstrc.d"
|
|
|
|
dunst_conf="$dunst_conf_dir/00-colorscheme.conf"
|
2020-02-15 15:52:14 +00:00
|
|
|
|
|
|
|
## Main Entrypoint
|
|
|
|
#
|
|
|
|
# Finds the right theme template file and starts theme
|
|
|
|
# switching and, if necessary, permanent setting processes.
|
|
|
|
main() {
|
2022-03-10 19:28:40 +00:00
|
|
|
dbg_msg $app "Starting Processor"
|
|
|
|
tfile="$path/$package/themes/base16-$theme.dunstrc"
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
if ! file_exists "$tfile"; then
|
|
|
|
dbg_msg $app "error" "Theme template $theme not found in package $package"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
if [[ "$permanent" == "true" ]]; then save; fi
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
dbg_msg $app "Processor Done"
|
2020-02-15 15:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Theme setter
|
|
|
|
#
|
|
|
|
# Takes care of permanently writing the desired
|
|
|
|
# base16 theme into application settings.
|
|
|
|
save() {
|
2022-03-10 19:28:40 +00:00
|
|
|
dbg_msg $app "Saving theme"
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
if [ ! -f "$dunst_conf" ]; then
|
|
|
|
mkdir -p "$dunst_conf_dir"
|
|
|
|
dbg_msg $app "$app colorscheme file not found. Creating new colorscheme file: $dunst_conf"
|
|
|
|
fi
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
# fix template theme name key for easier inclusion
|
|
|
|
echo "# Base16 $theme - dunst color config" >"$dunst_conf"
|
|
|
|
cat "$tfile" >>"$dunst_conf" || exit 1
|
|
|
|
echo "# Base16End $theme - dunst color config" >>"$dunst_conf"
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
dbg_msg $app "Saved theme to $dunst_conf"
|
2020-02-15 15:52:14 +00:00
|
|
|
|
2022-03-10 19:28:40 +00:00
|
|
|
save_post
|
2020-02-15 15:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
save_post() {
|
2022-03-10 19:28:40 +00:00
|
|
|
pkill dunst
|
|
|
|
dunst &
|
2020-02-15 15:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Safe sourcing: https://stackoverflow.com/a/12694189
|
|
|
|
DIR="${BASH_SOURCE%/*}"
|
|
|
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
|
|
|
# shellcheck source=utilities.sh
|
|
|
|
. "$DIR/utilities.sh"
|
|
|
|
## Dependency Checker
|
|
|
|
#
|
|
|
|
# Makes sure the processor is called for the correct
|
|
|
|
# base16 package, or refuses to run if it is not.
|
|
|
|
if printf '%s\n' "${dependency[@]}" | grep -q -P "^$package$"; then
|
2022-03-10 19:28:40 +00:00
|
|
|
main
|
2020-02-15 15:52:14 +00:00
|
|
|
else
|
2022-03-10 19:28:40 +00:00
|
|
|
dbg_msg $app "error" "Processor does not work for package $package"
|
2020-02-15 15:52:14 +00:00
|
|
|
fi
|