From edfb305ef305307daed90cac9188e9c7b7b429f8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 30 Jan 2020 21:58:31 +0100 Subject: [PATCH] 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. --- styler/.local/bin/styler | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/styler/.local/bin/styler b/styler/.local/bin/styler index 24ae60e..912079c 100755 --- a/styler/.local/bin/styler +++ b/styler/.local/bin/styler @@ -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