diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-05 15:09:42 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-05 15:09:42 +1100 |
| commit | ed804a5c3ca9fbda28b36c030acebd1bbea41265 (patch) | |
| tree | 278703366c3cfec79d99b317ed15d117a3693458 /scheme | |
| parent | scheme: random scheme when no args (diff) | |
| download | caelestia-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
Diffstat (limited to 'scheme')
| -rwxr-xr-x | scheme/main.fish | 74 |
1 files changed, 59 insertions, 15 deletions
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 |