diff options
| author | Paul Buetow <paul@buetow.org> | 2024-12-18 23:28:04 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-12-18 23:28:04 +0200 |
| commit | 6ad25a72b7c723cc07f2525e09d5fbb2f84c6a2b (patch) | |
| tree | cd9d7ba1e2f42cb24a03aaf41af737d698888d29 /gemfeed | |
| parent | a4fdf26eb3485c4d40e74d6dc50ddff1ebd8fc7d (diff) | |
better version
Diffstat (limited to 'gemfeed')
| -rw-r--r-- | gemfeed/2024-12-15-random-helix-themes.gmi | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/gemfeed/2024-12-15-random-helix-themes.gmi b/gemfeed/2024-12-15-random-helix-themes.gmi index 20ccede0..1c062c34 100644 --- a/gemfeed/2024-12-15-random-helix-themes.gmi +++ b/gemfeed/2024-12-15-random-helix-themes.gmi @@ -1,6 +1,6 @@ # Random Helix Themes -> Published at 2024-12-15T13:55:05+02:00 +> Published at 2024-12-15T13:55:05+02:00; Last updated 2024-12-18 I thought it would be fun to have a random Helix theme every time I open a new shell. Helix is the text editor I use. @@ -53,6 +53,40 @@ theme = "noctis" [paul@earth] ~ % ``` +## A better version + +> Update 2024-12-18: This is an improved version, which works cross platform (e.g., also on MacOS) and multiple theme directories: + +```sh +export EDITOR=hx +export VISUAL=$EDITOR +export GIT_EDITOR=$EDITOR +export HELIX_CONFIG_DIR=$HOME/.config/helix + +editor::helix::theme::get_random () { + for dir in $(hx --health \ + | awk '/^Runtime directories/ { print $3 }' | tr ';' ' '); do + if [ -d $dir/themes ]; then + ls $dir/themes + fi + done | grep -F .toml | sort -R | head -n 1 | cut -d. -f1 +} + +editor::helix::theme::set () { + local -r theme="$1"; shift + + local -r config_file=$HELIX_CONFIG_DIR/config.toml + + sed "/^theme =/ { s/.*/theme = \"$theme\"/; }" \ + $config_file > $config_file.tmp && + mv $config_file.tmp $config_file +} + +if [ -f $HELIX_CONFIG_DIR/config.toml ]; then + editor::helix::theme::set $(editor::helix::theme::get_random) +fi +``` + I hope you had some fun. E-Mail your comments to `paul@nospam.buetow.org` :-) => ../ Back to the main site |
