Add theme function
The theme function provides a quick but temporary switch to a specific theme. Themes can be applied with `styler theme [themename]`, they will be instantly applied to all enabled applications. They will be lost on restarts of the application or machine however. Themes can be applied permanently with `styler set [themename]`, they will be written into the application's settings. This *will* change things in your local filesystem, so be wary. Generally, processors should take the least invasive approach and use inclusion to append the theme to the application's other settings. But be *careful* with this option, and when in doubt double-check what the processors you have installed do before losing your settings.
This commit is contained in:
parent
acbe002f87
commit
edfb305ef3
1 changed files with 16 additions and 2 deletions
|
@ -5,13 +5,16 @@ readonly BASE_PATH="${STYLER_DATA_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/sty
|
|||
readonly PACKAGE_PATH="$BASE_PATH/packages"
|
||||
readonly PROCESSOR_PATH="$BASE_PATH/processors"
|
||||
|
||||
readonly VERSION="0.2.4"
|
||||
readonly VERSION="0.3.0"
|
||||
|
||||
main() {
|
||||
local cmd=""
|
||||
local ret=0
|
||||
|
||||
case "$1" in
|
||||
-t | --theme | theme)
|
||||
cmd="switch_theme"
|
||||
;;
|
||||
-s | --set | set)
|
||||
cmd="set_theme"
|
||||
;;
|
||||
|
@ -46,7 +49,11 @@ usage() {
|
|||
"" \
|
||||
" Options:" \
|
||||
"" \
|
||||
" -t | theme Temporarily switch theme. Use any valid base16 theme name (without base16- prefix)." \
|
||||
" Theme will be lost upon restart, or application restarts." \
|
||||
"" \
|
||||
" -s | set Set the theme. Use any valid base16 theme name (without base16- prefix)." \
|
||||
" Same as 'theme' option, but changes will be made permanent." \
|
||||
"" \
|
||||
" -d | download Download a base16 template into the package directory or download a processor16" \
|
||||
" into the processor directory. Use user/repo format to automatically pull from github." \
|
||||
|
@ -105,8 +112,15 @@ get_themes() {
|
|||
echo "$themes" | sed "s/.*\\/base16-//" | sed "s/\\..*//" | sort | uniq
|
||||
}
|
||||
|
||||
# temporarily switch theme, same thing as setting, only with permanence flag turned off for processors
|
||||
switch_theme() {
|
||||
set_theme "$1" "false"
|
||||
}
|
||||
|
||||
# call processors for all installed packages
|
||||
set_theme() {
|
||||
local theme="$1"
|
||||
local permanent="${2:-true}"
|
||||
|
||||
local packages
|
||||
packages="$(get_packages)"
|
||||
|
@ -134,7 +148,7 @@ set_theme() {
|
|||
# Compares application extension with existing processors and runs the appropriate processor if found
|
||||
processor=$(find "$PROCESSOR_PATH" -type f -name "theme_$appext")
|
||||
if [[ -f "$processor" ]]; then
|
||||
"$processor" "$PACKAGE_PATH" "$pkg" "$theme"
|
||||
"$processor" "$PACKAGE_PATH" "$pkg" "$theme" "$permanent"
|
||||
else
|
||||
printf "WARN: No processor found for application %s in %s. Make sure you install a processor for the application.\n" "$appext" "$PROCESSOR_PATH/" >&2
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue