2020-01-31 09:19:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
readonly dependency=("chriskempson/base16-shell")
|
2020-01-31 11:42:15 +00:00
|
|
|
readonly app="ansi-shell"
|
2020-01-31 09:19:25 +00:00
|
|
|
|
|
|
|
path="$1"
|
|
|
|
package="$2"
|
|
|
|
theme="$3"
|
2020-01-31 11:42:15 +00:00
|
|
|
# permanent="$4"
|
|
|
|
|
|
|
|
## 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/scripts/base16-$theme.sh"
|
2020-01-31 09:19:25 +00:00
|
|
|
|
|
|
|
if ! file_exists "$tfile"; then
|
2020-01-31 11:42:15 +00:00
|
|
|
dbg_msg $app "error" "Theme template $theme not found in package $package"
|
2020-01-31 09:19:25 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-31 11:42:15 +00:00
|
|
|
# not implemented
|
|
|
|
# if [[ "$permanent" == "true" ]]; then save; fi
|
|
|
|
theme
|
2020-01-31 09:19:25 +00:00
|
|
|
|
2020-01-31 11:42:15 +00:00
|
|
|
dbg_msg $app "Processor Done"
|
2020-01-31 09:19:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 11:42:15 +00:00
|
|
|
## Theme switcher
|
|
|
|
#
|
|
|
|
# Makes sure that if any application instance is
|
|
|
|
# currently running, it switches to new theme.
|
|
|
|
theme() {
|
|
|
|
dbg_msg $app "Switching theme"
|
2020-01-31 09:19:25 +00:00
|
|
|
# source "$tfile" -- works, but only for current terminal
|
|
|
|
# ANSI solution from: https://www.reddit.com/r/unixporn/comments/80nidw/bspwm_script_to_change_all_themes_on_demand/duxjw1e/
|
|
|
|
# only we can make use of kempson's scripts and send them to all terminals, so we don't have to manually
|
|
|
|
# sed the colors like sed -nE 's/^(color[0-9|_foreground|_background]+)="(.+)".*$/\1,\2/gp' $tfile
|
|
|
|
for term in /dev/pts/[0-9]*; do
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "$tfile" >"$term"
|
|
|
|
done
|
2020-01-31 11:42:15 +00:00
|
|
|
dbg_msg $app "Successfully switched theme"
|
2020-01-31 09:19:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 11:42:15 +00:00
|
|
|
### Theme setter
|
|
|
|
##
|
|
|
|
## Takes care of permanently writing the desired
|
|
|
|
## base16 theme into application settings.
|
|
|
|
#save() {
|
|
|
|
# dbg_msg $app "Saving theme"
|
|
|
|
# # saveroo
|
|
|
|
# dbg_msg $app "Sucessfully Saved theme"
|
|
|
|
#}
|
2020-01-31 09:19:25 +00:00
|
|
|
|
2020-01-31 11:42:15 +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() {
|
|
|
|
# dbg_msg $app "Including theme in configuration"
|
|
|
|
# # includeroo
|
|
|
|
# dbg_msg $app "Sucessfully included theme"
|
|
|
|
#}
|
|
|
|
|
|
|
|
## Dependency Checker
|
|
|
|
#
|
|
|
|
# Makes sure the processor is called for the correct
|
|
|
|
# base16 package, or refuses to run if it is not.
|
2020-01-31 09:19:25 +00:00
|
|
|
if printf '%s\n' "${dependency[@]}" | grep -q -P "^$package$"; then
|
2020-01-31 11:42:15 +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"
|
|
|
|
|
|
|
|
main
|
2020-01-31 09:19:25 +00:00
|
|
|
else
|
2020-01-31 11:42:15 +00:00
|
|
|
dbg_msg $app "error" "Processor does not work for package $package"
|
2020-01-31 09:19:25 +00:00
|
|
|
fi
|