#!/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. # # 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" ## 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" if ! file_exists "$tfile"; then dbg_msg $app "error" "Theme template $theme not found in package $package" exit 1 fi if [ ! -f "$zathuraconf" ]; then dbg_msg $app "error" "Zathura config file not found. Please make sure file exists: $zathuraconf" fi if [[ "$permanent" == "true" ]]; then save; fi dbg_msg $app "Processor Done" } ## Theme setter # # Takes care of permanently writing the desired # base16 theme into application settings. save() { dbg_msg $app "Saving theme" 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 cat "$tfile" >"${zathura_conf_dir}/${colorscheme_filename}" || exit 1 dbg_msg $app "Saved theme to ${zathura_conf_dir}/${colorscheme_filename}" } # 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 else dbg_msg $app "error" "Processor does not work for package $package" fi