irongit
hygoland/UserScripts/ZshChangeTheme.sh
69 lines2.0 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# Script for Oh my ZSH theme ( CTRL SHIFT O)
4
5# preview of theme can be view here: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
6# after choosing theme, TTY need to be closed and re-open
7
8# Variables
9iDIR="$HOME/.config/swaync/images"
10rofi_theme="$HOME/.config/rofi/config-zsh-theme.rasi"
11
12if [ -n "$(grep -i nixos < /etc/os-release)" ]; then
13 notify-send -i "$iDIR/note.png" "NOT Supported" "Sorry NixOS does not support this KooL feature"
14 exit 1
15fi
16
17themes_dir="$HOME/.oh-my-zsh/themes"
18file_extension=".zsh-theme"
19
20
21themes_array=($(find -L "$themes_dir" -type f -name "*$file_extension" -exec basename {} \; | sed -e "s/$file_extension//"))
22
23# Add "Random" option to the beginning of the array
24themes_array=("Random" "${themes_array[@]}")
25
26rofi_command="rofi -i -dmenu -config $rofi_theme"
27
28menu() {
29 for theme in "${themes_array[@]}"; do
30 echo "$theme"
31 done
32}
33
34main() {
35 choice=$(menu | ${rofi_command})
36
37 # if nothing selected, script won't change anything
38 if [ -z "$choice" ]; then
39 exit 0
40 fi
41
42 zsh_path="$HOME/.zshrc"
43 var_name="ZSH_THEME"
44
45 if [[ "$choice" == "Random" ]]; then
46 # Pick a random theme from the original themes_array (excluding "Random")
47 random_theme=${themes_array[$((RANDOM % (${#themes_array[@]} - 1) + 1))]}
48 theme_to_set="$random_theme"
49 notify-send -i "$iDIR/ja.png" "Random theme:" "selected: $random_theme"
50 else
51 # Set theme to the selected choice
52 theme_to_set="$choice"
53 notify-send -i "$iDIR/ja.png" "Theme selected:" "$choice"
54 fi
55
56 if [ -f "$zsh_path" ]; then
57 sed -i "s/^$var_name=.*/$var_name=\"$theme_to_set\"/" "$zsh_path"
58 notify-send -i "$iDIR/ja.png" "OMZ theme" "applied. restart your terminal"
59 else
60 notify-send -i "$iDIR/error.png" "E-R-R-O-R" "~.zshrc file not found!"
61 fi
62}
63
64# Check if rofi is already running
65if pidof rofi > /dev/null; then
66 pkill rofi
67fi
68
69main