summaryrefslogtreecommitdiff
path: root/gemfeed/2024-12-15-random-helix-themes.gmi
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-21 10:55:25 +0200
committerPaul Buetow <paul@buetow.org>2025-02-21 10:55:25 +0200
commit5a76af565ea910512b0418c56437467068821fd6 (patch)
treed8ee7610db5f698703d5891eb9b6aabd1f699f14 /gemfeed/2024-12-15-random-helix-themes.gmi
parenta30460cc038708e3a01cbe8cf4d90c6572e26784 (diff)
parent75655782fe8ad0b8b9b5fd26a6837e8a745b7268 (diff)
Merge branch 'content-gemtext' of codeberg.org:snonux/foo.zone into content-gemtext
Diffstat (limited to 'gemfeed/2024-12-15-random-helix-themes.gmi')
-rw-r--r--gemfeed/2024-12-15-random-helix-themes.gmi92
1 files changed, 92 insertions, 0 deletions
diff --git a/gemfeed/2024-12-15-random-helix-themes.gmi b/gemfeed/2024-12-15-random-helix-themes.gmi
new file mode 100644
index 00000000..1c062c34
--- /dev/null
+++ b/gemfeed/2024-12-15-random-helix-themes.gmi
@@ -0,0 +1,92 @@
+# Random Helix Themes
+
+> 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.
+
+=> https://helix-editor.com/
+
+So I put this into my `zsh` dotfiles (in some `editor.zsh.source` in my `~` directory):
+
+```sh
+export EDITOR=hx
+export VISUAL=$EDITOR
+export GIT_EDITOR=$EDITOR
+export HELIX_CONFIG_DIR=$HOME/.config/helix
+
+editor::helix::random_theme () {
+ # May add more theme search paths based on OS. This one is
+ # for Fedora Linux, but there is also MacOS, etc.
+ local -r theme_dir=/usr/share/helix/runtime/themes
+ if [ ! -d $theme_dir ]; then
+ echo "Helix theme dir $theme_dir doesnt exist"
+ return 1
+ fi
+
+ local -r config_file=$HELIX_CONFIG_DIR/config.toml
+ local -r random_theme="$(basename "$(ls $theme_dir \
+ | grep -v random.toml | grep .toml | sort -R \
+ | head -n 1)" | cut -d. -f1)"
+
+ sed "/^theme =/ { s/.*/theme = \"$random_theme\"/; }" \
+ $config_file > $config_file.tmp &&
+ mv $config_file.tmp $config_file
+}
+
+if [ -f $HELIX_CONFIG_DIR/config.toml ]; then
+ editor::helix::random_theme
+fi
+```
+
+So every time I open a new terminal or shell, `editor::helix::random_theme` gets called, which randomly selects a theme from all installed ones and updates the helix config accordingly.
+
+```sh
+[paul@earth] ~ % editor::helix::random_theme
+[paul@earth] ~ % head -n 1 ~/.config/helix/config.toml
+theme = "jellybeans"
+[paul@earth] ~ % editor::helix::random_theme
+[paul@earth] ~ % head -n 1 ~/.config/helix/config.toml
+theme = "rose_pine"
+[paul@earth] ~ % editor::helix::random_theme
+[paul@earth] ~ % head -n 1 ~/.config/helix/config.toml
+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