summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-05 15:09:42 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-05 15:09:42 +1100
commited804a5c3ca9fbda28b36c030acebd1bbea41265 (patch)
tree278703366c3cfec79d99b317ed15d117a3693458
parentscheme: random scheme when no args (diff)
downloadcaelestia-cli-ed804a5c3ca9fbda28b36c030acebd1bbea41265.tar.gz
caelestia-cli-ed804a5c3ca9fbda28b36c030acebd1bbea41265.tar.bz2
caelestia-cli-ed804a5c3ca9fbda28b36c030acebd1bbea41265.zip
scheme: refactor schemes
Schemes can have multiple flavours, and each flavour can have a light/dark mode
-rw-r--r--.gitignore2
-rw-r--r--completions/caelestia.fish17
-rw-r--r--data/schemes/catppuccin/frappe/dark.txt (renamed from data/schemes/frappe.txt)0
-rw-r--r--data/schemes/catppuccin/latte/light.txt (renamed from data/schemes/latte.txt)0
-rw-r--r--data/schemes/catppuccin/macchiato/dark.txt (renamed from data/schemes/macchiato.txt)0
-rw-r--r--data/schemes/catppuccin/mocha/dark.txt (renamed from data/schemes/mocha.txt)0
-rw-r--r--data/schemes/onedark/dark.txt (renamed from data/schemes/onedark.txt)0
-rwxr-xr-xscheme/main.fish74
-rwxr-xr-xwallpaper.fish9
9 files changed, 81 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 16a1db5..8c7f4ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1 @@
-/data/schemes/dynamic.txt
+/data/schemes/dynamic/
diff --git a/completions/caelestia.fish b/completions/caelestia.fish
index 2eac75c..b2a2916 100644
--- a/completions/caelestia.fish
+++ b/completions/caelestia.fish
@@ -51,8 +51,23 @@ set -l commands workspace workspacegroup movetoworkspace movetoworkspacegroup
complete -c caelestia -n "$seen workspace-action && not $seen $commands" -a "$commands"
# Scheme
-set -l commands dynamic mocha macchiato frappe latte
+set -q XDG_DATA_HOME && set -l data_dir $XDG_DATA_HOME || set -l data_dir $HOME/.local/share
+set -l scheme_dir $data_dir/caelestia/scripts/data/schemes
+set -l commands (basename -a (find $scheme_dir/ -mindepth 1 -maxdepth 1 -type d))
complete -c caelestia -n "$seen scheme && not $seen $commands" -a "$commands"
+for scheme in $commands
+ set -l flavours (basename -a (find $scheme_dir/$scheme/ -mindepth 1 -maxdepth 1 -type d) 2> /dev/null)
+ set -l modes (basename -s .txt (find $scheme_dir/$scheme/ -mindepth 1 -maxdepth 1 -type f) 2> /dev/null)
+ if test -n "$modes"
+ complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $modes" -a "$modes"
+ else
+ complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $flavours" -a "$flavours"
+ for flavour in $flavours
+ set -l modes (basename -s .txt (find $scheme_dir/$scheme/$flavour/ -mindepth 1 -maxdepth 1 -type f))
+ complete -c caelestia -n "$seen scheme && $seen $scheme && $seen $flavour && not $seen $modes" -a "$modes"
+ end
+ end
+end
# Record
set -l not_seen "$seen record && not $has_opt -s h help"
diff --git a/data/schemes/frappe.txt b/data/schemes/catppuccin/frappe/dark.txt
index b572562..b572562 100644
--- a/data/schemes/frappe.txt
+++ b/data/schemes/catppuccin/frappe/dark.txt
diff --git a/data/schemes/latte.txt b/data/schemes/catppuccin/latte/light.txt
index ec3b601..ec3b601 100644
--- a/data/schemes/latte.txt
+++ b/data/schemes/catppuccin/latte/light.txt
diff --git a/data/schemes/macchiato.txt b/data/schemes/catppuccin/macchiato/dark.txt
index ad234a2..ad234a2 100644
--- a/data/schemes/macchiato.txt
+++ b/data/schemes/catppuccin/macchiato/dark.txt
diff --git a/data/schemes/mocha.txt b/data/schemes/catppuccin/mocha/dark.txt
index 77e96eb..77e96eb 100644
--- a/data/schemes/mocha.txt
+++ b/data/schemes/catppuccin/mocha/dark.txt
diff --git a/data/schemes/onedark.txt b/data/schemes/onedark/dark.txt
index 6485f5e..6485f5e 100644
--- a/data/schemes/onedark.txt
+++ b/data/schemes/onedark/dark.txt
diff --git a/scheme/main.fish b/scheme/main.fish
index 26063d7..7b0dc8f 100755
--- a/scheme/main.fish
+++ b/scheme/main.fish
@@ -1,32 +1,76 @@
#!/bin/fish
+# Usage:
+# caelestia scheme <scheme> <flavour> [mode]
+# caelestia scheme <scheme> [flavour]
+# caelestia scheme [scheme]
+
+function set-scheme -a path name mode
+ mkdir -p $C_STATE/scheme
+
+ # Update scheme colours
+ cp $path $C_STATE/scheme/current.txt
+
+ # Update scheme name
+ echo -n $name > $C_STATE/scheme/current-name.txt
+
+ # Update scheme mode
+ echo -n $mode > $C_STATE/scheme/current-mode.txt
+
+ log "Changed scheme to $name ($mode)"
+end
+
set -l src (dirname (status filename))/..
+set -l schemes $src/data/schemes
. $src/util.fish
-set -l valid_schemes (path change-extension '' $src/data/schemes/* | sed 's!.*/!!')
-set -l light_schemes latte
+set -l valid_schemes (basename -a $schemes/*)
test -z "$argv" && set -l argv[1] (random choice $valid_schemes)
if contains -- "$argv[1]" $valid_schemes
- mkdir -p $C_STATE/scheme
+ set -l flavours (basename -a (find $schemes/$argv[1]/ -mindepth 1 -maxdepth 1 -type d) 2> /dev/null)
+ set -l modes (basename -s .txt (find $schemes/$argv[1]/ -mindepth 1 -maxdepth 1 -type f) 2> /dev/null)
- # Update scheme colours
- cp $src/data/schemes/$argv[1].txt $C_STATE/scheme/current.txt
-
- # Update scheme name
- echo -n $argv[1] > $C_STATE/scheme/current-name.txt
+ if test -n "$modes"
+ # Scheme only has one flavour, so second arg is mode
+ if test -z "$argv[2]"
+ # Try to use current mode if not provided and current mode exists for flavour, otherwise random mode
+ set argv[2] (cat $C_STATE/scheme/current-mode.txt 2> /dev/null)
+ contains -- "$argv[2]" $modes || set argv[2] (random choice $modes)
+ end
- # Update scheme mode
- if test $argv[1] = dynamic
- set colour_scheme (cat $C_STATE/scheme/dynamic-mode.txt)
+ if contains -- "$argv[2]" $modes
+ # Provided valid mode
+ set-scheme $schemes/$argv[1]/$argv[2].txt $argv[1] $argv[2]
+ else
+ error "Invalid mode for $argv[1]: $argv[2]"
+ end
else
- contains -- "$argv[1]" $light_schemes && set colour_scheme light || set colour_scheme dark
- end
- echo -n $colour_scheme > $C_STATE/scheme/current-mode.txt
+ # Scheme has multiple flavours, so second arg is flavour
+ test -z "$argv[2]" && set -l argv[2] (random choice $flavours)
- log "Changed scheme to $argv[1]"
+ if contains -- "$argv[2]" $flavours
+ # Provided valid flavour
+ set -l modes (basename -s .txt $schemes/$argv[1]/$argv[2]/*.txt)
+ if test -z "$argv[3]"
+ # Try to use current mode if not provided and current mode exists for flavour, otherwise random mode
+ set argv[3] (cat $C_STATE/scheme/current-mode.txt 2> /dev/null)
+ contains -- "$argv[3]" $modes || set argv[3] (random choice $modes)
+ end
+
+ if contains -- "$argv[3]" $modes
+ # Provided valid mode
+ set-scheme $schemes/$argv[1]/$argv[2]/$argv[3].txt $argv[1]-$argv[2] $argv[3]
+ else
+ error "Invalid mode for $argv[1] $argv[2]: $argv[3]"
+ end
+ else
+ # Invalid flavour
+ error "Invalid flavour for $argv[1]: $argv[2]"
+ end
+ end
else
error "Invalid scheme: $argv[1]"
end
diff --git a/wallpaper.fish b/wallpaper.fish
index d6c146e..0db1f7d 100755
--- a/wallpaper.fish
+++ b/wallpaper.fish
@@ -108,10 +108,11 @@ else
# Generate colour scheme for wallpaper
set -l src (dirname (status filename))
- set -q _flag_T && set -l theme --theme $_flag_T
- $src/scheme/gen-scheme.fish $theme $chosen_wallpaper > $src/data/schemes/dynamic.txt
- if test -f $C_STATE/scheme/current-name.txt -a "$(cat $C_STATE/scheme/current-name.txt)" = 'dynamic'
- caelestia scheme dynamic > /dev/null
+ mkdir -p $src/data/schemes/dynamic
+ $src/scheme/gen-scheme.fish --theme dark $chosen_wallpaper > $src/data/schemes/dynamic/dark.txt
+ $src/scheme/gen-scheme.fish --theme light $chosen_wallpaper > $src/data/schemes/dynamic/light.txt
+ if test "$(cat $C_STATE/scheme/current-name.txt 2> /dev/null)" = 'dynamic'
+ caelestia scheme dynamic $_flag_T > /dev/null
end
# Store the wallpaper chosen