Skip to content

Commit

Permalink
plugins: Add Theme plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Oct 2, 2024
1 parent f53beb6 commit f419dbe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/themes/README.md
Original file line number Diff line number Diff line change
@@ -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 <theme_name>` - Changes the theme to specified theme.

`theme ` - Changes the theme to some random theme.

`lstheme ` - Lists installed themes.
33 changes: 33 additions & 0 deletions plugins/themes/themes.plugin.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f419dbe

Please sign in to comment.