baseproc16-default/theme_zathura

83 lines
2.6 KiB
Text
Raw Permalink Normal View History

2020-02-27 20:35:51 +00:00
#!/usr/bin/env bash
readonly dependency=("nicodebo/base16-zathura")
readonly app="zathura"
#
# zathura now allows including other files into its
# main configuration file. That means we can be less
# intrusive about the colorscheme changes and only insert
# the include line, adding any colorscheme options
# in a completely different file.
2020-02-27 20:35:51 +00:00
#
# In general, the processor looks for a specific line in the
# following format:
# '# Base16 [theme name] - zathura color config'
# from which it will delete everything until it finds a line:
# '# Base16End [theme name] - zathura color config'
# 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"
zathura_conf_dir="$HOME/.config/zathura"
zathuraconf="$zathura_conf_dir/zathurarc"
colorscheme_filename="colorscheme"
2020-02-27 20:35:51 +00:00
## 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/build_schemes/base16-$theme.config"
2020-02-27 20:35:51 +00:00
if ! file_exists "$tfile"; then
dbg_msg $app "error" "Theme template $theme not found in package $package"
exit 1
fi
2020-02-27 20:35:51 +00:00
if [ ! -f "$zathuraconf" ]; then
dbg_msg $app "error" "Zathura config file not found. Please make sure file exists: $zathuraconf"
fi
2020-02-27 20:35:51 +00:00
if [[ "$permanent" == "true" ]]; then save; fi
2020-02-27 20:35:51 +00:00
dbg_msg $app "Processor Done"
2020-02-27 20:35:51 +00:00
}
## Theme setter
#
# Takes care of permanently writing the desired
# base16 theme into application settings.
save() {
dbg_msg $app "Saving theme"
2020-02-27 20:35:51 +00:00
if ! $(grep -qe "^include $colorscheme_filename" "$zathuraconf"); then
dbg_msg $app "No include directive for colorscheme file found in configuration file. Adding it now."
printf "\ninclude %s\n" "$colorscheme_filename" >>"$zathuraconf"
else
dbg_msg $app "Found include directive for colorscheme file. No operation necessary."
fi
2020-02-27 20:35:51 +00:00
cat "$tfile" >"${zathura_conf_dir}/${colorscheme_filename}" || exit 1
2020-02-27 20:35:51 +00:00
dbg_msg $app "Saved theme to ${zathura_conf_dir}/${colorscheme_filename}"
2020-02-27 20:35:51 +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
main
2020-02-27 20:35:51 +00:00
else
dbg_msg $app "error" "Processor does not work for package $package"
2020-02-27 20:35:51 +00:00
fi