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 +}