Update dunst to use drop-in configuration files
dunst theming now uses the newly introduced drop-in files for dunst (v1.8.0) which allow less intrusive theming. Now simply drops a new colorscheme file in the right location instead of meddling with the main configuration file.
This commit is contained in:
parent
12474e85dd
commit
b780cefea8
1 changed files with 34 additions and 58 deletions
92
theme_dunst
92
theme_dunst
|
@ -2,9 +2,13 @@
|
|||
readonly dependency=("khamer/base16-dunst")
|
||||
readonly app="dunst"
|
||||
#
|
||||
# Alacritty does not support including other files into
|
||||
# its configuration yet. As such, this processor needs to
|
||||
# change the user's configuration file *itself*.
|
||||
# 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.
|
||||
#
|
||||
# This will generally not be a problem, though it can lead
|
||||
# to corrupted configurations in exceptional circumstances
|
||||
|
@ -13,9 +17,9 @@ readonly app="dunst"
|
|||
#
|
||||
# In general, the processor looks for a specific line in the
|
||||
# following format:
|
||||
# '# Base16 [theme name] - alacritty color config'
|
||||
# '# Base16 [theme name] - dunst color config'
|
||||
# from which it will delete everything until it finds a line:
|
||||
# '# Base16End [theme name] - alacritty color config'
|
||||
# '# Base16End [theme name] - dunst color config'
|
||||
# So, if you don't want to lose anything -
|
||||
# Do NOT put anything important between those two lines.
|
||||
|
||||
|
@ -24,28 +28,25 @@ package="$2"
|
|||
theme="$3"
|
||||
permanent="$4"
|
||||
|
||||
dunst_conf="$HOME/.config/dunst/dunstrc"
|
||||
dunst_conf_dir="$HOME/.config/dunst/dunstrc.d"
|
||||
dunst_conf="$dunst_conf_dir/00-colorscheme.conf"
|
||||
|
||||
## Main Entrypoint
|
||||
#
|
||||
# Finds the right theme template file and starts theme
|
||||
# switching and, if necessary, permanent setting processes.
|
||||
main() {
|
||||
dbg_msg $app "Starting Processor"
|
||||
tfile="$path/$package/themes/base16-$theme.dunstrc"
|
||||
dbg_msg $app "Starting Processor"
|
||||
tfile="$path/$package/themes/base16-$theme.dunstrc"
|
||||
|
||||
if ! file_exists "$tfile"; then
|
||||
dbg_msg $app "error" "Theme template $theme not found in package $package"
|
||||
exit 1
|
||||
fi
|
||||
if ! file_exists "$tfile"; then
|
||||
dbg_msg $app "error" "Theme template $theme not found in package $package"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$dunst_conf" ]; then
|
||||
dbg_msg $app "error" "$app config file not found. Please make sure file exists: $dunst_conf"
|
||||
fi
|
||||
if [[ "$permanent" == "true" ]]; then save; fi
|
||||
|
||||
if [[ "$permanent" == "true" ]]; then save; fi
|
||||
|
||||
dbg_msg $app "Processor Done"
|
||||
dbg_msg $app "Processor Done"
|
||||
}
|
||||
|
||||
## Theme setter
|
||||
|
@ -53,51 +54,26 @@ main() {
|
|||
# Takes care of permanently writing the desired
|
||||
# base16 theme into application settings.
|
||||
save() {
|
||||
dbg_msg $app "Saving theme"
|
||||
dbg_msg $app "Saving theme"
|
||||
|
||||
startline="$(grep -ne '^# Base16 .*- dunst color config$' "$dunst_conf" | cut -f1 -d:)"
|
||||
endline="$(grep -ne '^# Base16End .*- dunst color config$' "$dunst_conf" | cut -f1 -d:)"
|
||||
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
|
||||
|
||||
tmpfile="$dunst_conf.tmp"
|
||||
tmptheme="$dunst_conf.thm.tmp"
|
||||
echo "" >"$tmpfile"
|
||||
echo "" >"$tmptheme"
|
||||
# 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"
|
||||
|
||||
if [[ -n "$startline" && -z "$endline" ]] || [[ -z "$startline" && -n "$endline" ]] || [[ "$startline" -gt "$endline" ]]; then
|
||||
dbg_msg $app "error" "Base 16 Pattern not correctly recognized in file: $dunst_conf. Please make sure pattern begins with # Base16 and ends with # Base16End and only exists once in the file. No changes to file made."
|
||||
cat "$dunst_conf" >"$tmpfile" || exit 1
|
||||
dbg_msg $app "Saved theme to $dunst_conf"
|
||||
|
||||
elif [[ -z "$startline" && -z "$endline" ]]; then
|
||||
dbg_msg $app "warn" "No previous Base16 pattern found in file: $dunst_conf. If this is your first time running the processor, ignore this warning."
|
||||
cat "$dunst_conf" >"$tmpfile" || exit 1
|
||||
|
||||
else
|
||||
# remove old lines of any base16 theme
|
||||
sed -e "$startline,$endline d" "$dunst_conf" >"$tmpfile" || exit 1
|
||||
|
||||
fi
|
||||
|
||||
# fix template theme name key for easier inclusion
|
||||
echo "# Base16 $theme - dunst color config" >"$tmptheme"
|
||||
cat "$tfile" >>"$tmptheme" || exit 1
|
||||
echo "# Base16End $theme - dunst color config" >>"$tmptheme"
|
||||
|
||||
# combine both into final config file
|
||||
# replace original file with new colorscheme-added version
|
||||
|
||||
cat "$tmpfile" "$tmptheme" >"$dunst_conf"
|
||||
|
||||
[ -f "$tmptheme" ] && rm "$tmptheme"
|
||||
[ -f "$tmpfile" ] && rm "$tmpfile"
|
||||
|
||||
dbg_msg $app "Saved theme to $dunst_conf"
|
||||
|
||||
save_post
|
||||
save_post
|
||||
}
|
||||
|
||||
save_post() {
|
||||
pkill dunst
|
||||
dunst &
|
||||
pkill dunst
|
||||
dunst &
|
||||
}
|
||||
|
||||
# Safe sourcing: https://stackoverflow.com/a/12694189
|
||||
|
@ -110,7 +86,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
|||
# 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
|
||||
main
|
||||
main
|
||||
else
|
||||
dbg_msg $app "error" "Processor does not work for package $package"
|
||||
dbg_msg $app "error" "Processor does not work for package $package"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue