From f419dbe345f6582273d8498c0a442c1880058a6a Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 00:23:59 -0400 Subject: [PATCH 1/4] plugins: Add Theme plugin --- plugins/themes/README.md | 19 +++++++++++++++++++ plugins/themes/themes.plugin.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 plugins/themes/README.md create mode 100644 plugins/themes/themes.plugin.sh diff --git a/plugins/themes/README.md b/plugins/themes/README.md new file mode 100644 index 000000000..e9e6ca888 --- /dev/null +++ b/plugins/themes/README.md @@ -0,0 +1,19 @@ +# Themes Plugin + +This plugin allows you to change Oh-My-Bash themes on the go. + +To use it, add `themes` to the plugins array in your `.bashrc` file: + +``` +plugins=(... themes) +``` + +This is based off the [themes oh-my-zsh plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/themes). + +## Usage + +`theme ` - Changes the theme to specified theme. + +`theme ` - Changes the theme to some random theme. + +`lstheme ` - Lists installed themes. diff --git a/plugins/themes/themes.plugin.sh b/plugins/themes/themes.plugin.sh new file mode 100644 index 000000000..364f9d84d --- /dev/null +++ b/plugins/themes/themes.plugin.sh @@ -0,0 +1,33 @@ +#! bash oh-my-bash.module + +# Load the given theme, or a random one if none is provided. +function theme() { + local desired_theme="$1" + + # Random + if [[ -z "$desired_theme" ]]; then + local theme_files + _omb_util_glob_expand theme_files '"$OSH"/themes/*/*.theme.sh' + theme_files=("${theme_files[@]}") + + if ((${#theme_files[@]})); then + local random_theme=${theme_files[RANDOM%${#theme_files[@]}]} + desired_theme=$(basename $(dirname "$random_theme")) + echo "${_omb_term_reset}theme ${_omb_term_bold}${desired_theme}$_omb_term_reset" + else + echo "No themes found." + return 1 + fi + fi + + _omb_module_require_theme "$desired_theme" +} + +# List all available themes +function lstheme() { + local theme_files + _omb_util_glob_expand theme_files '"$OSH"/themes/*/*.theme.sh' + for i in "${theme_files[@]}"; do + echo $(basename $(dirname "$i")) + done +} From 2eccd6377d48449b8e04fa4f0e8c2ad1d3c1fb74 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 01:15:43 -0400 Subject: [PATCH 2/4] Move to Usage: omb theme Available commands: list List all available themes set Set the given theme in your .bashrc file use Load the given theme --- lib/cli.bash | 40 +++++++++++++++++++++++++++++++-- plugins/themes/README.md | 19 ---------------- plugins/themes/themes.plugin.sh | 33 --------------------------- 3 files changed, 38 insertions(+), 54 deletions(-) delete mode 100644 plugins/themes/README.md delete mode 100644 plugins/themes/themes.plugin.sh diff --git a/lib/cli.bash b/lib/cli.bash index 111da2a6d..8af6ece19 100644 --- a/lib/cli.bash +++ b/lib/cli.bash @@ -18,7 +18,43 @@ function _omb_cmd_reload { echo 'Not yet implemented' } function _omb_cmd_theme { - echo 'Not yet implemented' + case "$1" in + list) + local -a available_themes + _comp_cmd_omb__get_available_themes + for theme in "${available_themes[@]}"; do + echo "$theme" + done + ;; + use) + local theme=$2 + if [[ -z "$theme" ]]; then + echo 'Usage: omb theme use ' + return 2 + fi + local -a available_themes + _comp_cmd_omb__get_available_themes + for i in "${available_themes[@]}"; do + if [ "$i" == "$theme" ]; then + _omb_module_require_theme "$theme" + return 0 + fi + done + echo "Theme '$theme' not found" + ;; + set) + echo 'Not yet implemented' + ;; + *) + echo 'Usage: omb theme ' + echo '' + echo 'Available commands:' + echo ' list List all available themes' + echo ' set Set the given theme in your .bashrc file' + echo ' use Load the given theme' + return 2 + ;; + esac } function _omb_cmd_update { echo 'Not yet implemented' @@ -161,7 +197,7 @@ function _comp_cmd_omb { theme) local -a subcmds=( 'list:List themes' - 'set:Set a theme in your .zshrc file' + 'set:Set a theme in your .bashrc file' 'use:Load a theme' ) _comp_cmd_omb__describe 'command' subcmds ;; diff --git a/plugins/themes/README.md b/plugins/themes/README.md deleted file mode 100644 index e9e6ca888..000000000 --- a/plugins/themes/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Themes Plugin - -This plugin allows you to change Oh-My-Bash themes on the go. - -To use it, add `themes` to the plugins array in your `.bashrc` file: - -``` -plugins=(... themes) -``` - -This is based off the [themes oh-my-zsh plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/themes). - -## Usage - -`theme ` - Changes the theme to specified theme. - -`theme ` - Changes the theme to some random theme. - -`lstheme ` - Lists installed themes. diff --git a/plugins/themes/themes.plugin.sh b/plugins/themes/themes.plugin.sh deleted file mode 100644 index 364f9d84d..000000000 --- a/plugins/themes/themes.plugin.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! bash oh-my-bash.module - -# Load the given theme, or a random one if none is provided. -function theme() { - local desired_theme="$1" - - # Random - if [[ -z "$desired_theme" ]]; then - local theme_files - _omb_util_glob_expand theme_files '"$OSH"/themes/*/*.theme.sh' - theme_files=("${theme_files[@]}") - - if ((${#theme_files[@]})); then - local random_theme=${theme_files[RANDOM%${#theme_files[@]}]} - desired_theme=$(basename $(dirname "$random_theme")) - echo "${_omb_term_reset}theme ${_omb_term_bold}${desired_theme}$_omb_term_reset" - else - echo "No themes found." - return 1 - fi - fi - - _omb_module_require_theme "$desired_theme" -} - -# List all available themes -function lstheme() { - local theme_files - _omb_util_glob_expand theme_files '"$OSH"/themes/*/*.theme.sh' - for i in "${theme_files[@]}"; do - echo $(basename $(dirname "$i")) - done -} From be832046a674c2f202a2790659cc8211debc0190 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 01:47:33 -0400 Subject: [PATCH 3/4] Update lib/cli.bash Co-authored-by: Koichi Murase --- lib/cli.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.bash b/lib/cli.bash index 8af6ece19..849454c48 100644 --- a/lib/cli.bash +++ b/lib/cli.bash @@ -29,7 +29,7 @@ function _omb_cmd_theme { use) local theme=$2 if [[ -z "$theme" ]]; then - echo 'Usage: omb theme use ' + _omb_util_print 'Usage: omb theme use ' >&2 return 2 fi local -a available_themes From e4940e14e85bfcc7a17f53427d877786afeb446a Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 01:48:21 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Koichi Murase --- lib/cli.bash | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/cli.bash b/lib/cli.bash index 849454c48..560d87dd4 100644 --- a/lib/cli.bash +++ b/lib/cli.bash @@ -18,16 +18,14 @@ function _omb_cmd_reload { echo 'Not yet implemented' } function _omb_cmd_theme { - case "$1" in + case "${1-}" in list) local -a available_themes _comp_cmd_omb__get_available_themes - for theme in "${available_themes[@]}"; do - echo "$theme" - done + _omb_util_print_lines "${available_themes[@]}" ;; use) - local theme=$2 + local theme=${2-} if [[ -z "$theme" ]]; then _omb_util_print 'Usage: omb theme use ' >&2 return 2 @@ -40,18 +38,19 @@ function _omb_cmd_theme { return 0 fi done - echo "Theme '$theme' not found" + _omb_util_print "Theme '$theme' not found" ;; set) echo 'Not yet implemented' ;; *) - echo 'Usage: omb theme ' - echo '' - echo 'Available commands:' - echo ' list List all available themes' - echo ' set Set the given theme in your .bashrc file' - echo ' use Load the given theme' + _omb_util_print_lines \ + 'Usage: omb theme ' \ + '' \ + 'Available commands:' \ + ' list List all available themes' \ + ' set Set the given theme in your .bashrc file' \ + ' use Load the given theme' return 2 ;; esac