From 4838aecb75c26b558155e4d2a5e1f6fbcc5166c2 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 30 Jan 2020 19:49:37 +0100 Subject: [PATCH] Add list function to styler Can list available themes, packages, and processors. Invoked by `styler list` and then the intended target. When invoked without any valid target will remind the user to supply one. `list`, `--list`, `-l` are aliases and perform the same function. Examples: `styler list themes` `styler --list packages` `styler -l processors` --- styler/.local/bin/styler | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/styler/.local/bin/styler b/styler/.local/bin/styler index f094b7d..650be57 100755 --- a/styler/.local/bin/styler +++ b/styler/.local/bin/styler @@ -1,7 +1,6 @@ #!/usr/bin/env bash readonly BASE_PATH="${STYLER_DATA_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/styler}" -readonly DEBUG="${STYLER_ENABLE_DEBUG_MODE:-false}" readonly PACKAGE_PATH="$BASE_PATH/packages" readonly PROCESSOR_PATH="$BASE_PATH/processors" @@ -14,6 +13,9 @@ main() { -s | --set | set) cmd="set_theme" ;; + -l | --list | list) + cmd="list" + ;; -v | --version | version) printf "Program theming script.\n\n©Marty Oehme\n\nVersion: 0.1.0\n" exit 0 @@ -75,6 +77,13 @@ get_processors() { done } +# retrieves all installed themes from all packages, appends applications they exist for +get_themes() { + local themes + themes=$(find "$PACKAGE_PATH" -type f -name 'base16-*') + echo "$themes" | sed "s/.*\\/base16-//" | sed "s/\\..*//" | sort | uniq +} + set_theme() { local theme="$1" @@ -112,4 +121,23 @@ set_theme() { done } +list() { + local selected="$1" + + case "$selected" in + packages) + get_packages + ;; + processors) + get_processors + ;; + themes) + get_themes + ;; + *) + echo "Please select one of packages | processors | themes to list." + ;; + esac +} + main "$@"