forked from Shinonome/caelestia-cli
scheme: fix random
This commit is contained in:
+26
-21
@@ -25,52 +25,57 @@ set -l schemes $src/data/schemes
|
||||
|
||||
. $src/util.fish
|
||||
|
||||
set -l scheme $argv[1]
|
||||
set -l flavour $argv[2]
|
||||
set -l mode $argv[3]
|
||||
|
||||
set -l valid_schemes (basename -a $schemes/*)
|
||||
|
||||
test -z "$argv" && set -l argv[1] (random choice $valid_schemes)
|
||||
test -z "$scheme" && set -l scheme (random choice $valid_schemes)
|
||||
|
||||
if contains -- "$argv[1]" $valid_schemes
|
||||
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)
|
||||
if contains -- "$scheme" $valid_schemes
|
||||
set -l flavours (basename -a (find $schemes/$scheme/ -mindepth 1 -maxdepth 1 -type d) 2> /dev/null)
|
||||
set -l modes (basename -s .txt (find $schemes/$scheme/ -mindepth 1 -maxdepth 1 -type f) 2> /dev/null)
|
||||
|
||||
if test -n "$modes"
|
||||
# Scheme only has one flavour, so second arg is mode
|
||||
if test -z "$argv[2]"
|
||||
set -l mode $flavour
|
||||
if test -z "$mode"
|
||||
# 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)
|
||||
set $mode (cat $C_STATE/scheme/current-mode.txt 2> /dev/null)
|
||||
contains -- "$mode" $modes || set mode (random choice $modes)
|
||||
end
|
||||
|
||||
if contains -- "$argv[2]" $modes
|
||||
if contains -- "$mode" $modes
|
||||
# Provided valid mode
|
||||
set-scheme $schemes/$argv[1]/$argv[2].txt $argv[1] $argv[2]
|
||||
set-scheme $schemes/$scheme/$mode.txt $scheme $mode
|
||||
else
|
||||
error "Invalid mode for $argv[1]: $argv[2]"
|
||||
error "Invalid mode for $scheme: $mode"
|
||||
end
|
||||
else
|
||||
# Scheme has multiple flavours, so second arg is flavour
|
||||
test -z "$argv[2]" && set -l argv[2] (random choice $flavours)
|
||||
test -z "$flavour" && set -l flavour (random choice $flavours)
|
||||
|
||||
if contains -- "$argv[2]" $flavours
|
||||
if contains -- "$flavour" $flavours
|
||||
# Provided valid flavour
|
||||
set -l modes (basename -s .txt $schemes/$argv[1]/$argv[2]/*.txt)
|
||||
if test -z "$argv[3]"
|
||||
set -l modes (basename -s .txt $schemes/$scheme/$flavour/*.txt)
|
||||
if test -z "$mode"
|
||||
# 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)
|
||||
set mode (cat $C_STATE/scheme/current-mode.txt 2> /dev/null)
|
||||
contains -- "$mode" $modes || set mode (random choice $modes)
|
||||
end
|
||||
|
||||
if contains -- "$argv[3]" $modes
|
||||
if contains -- "$mode" $modes
|
||||
# Provided valid mode
|
||||
set-scheme $schemes/$argv[1]/$argv[2]/$argv[3].txt $argv[1]-$argv[2] $argv[3]
|
||||
set-scheme $schemes/$scheme/$flavour/$mode.txt $scheme-$flavour $mode
|
||||
else
|
||||
error "Invalid mode for $argv[1] $argv[2]: $argv[3]"
|
||||
error "Invalid mode for $scheme $flavour: $mode"
|
||||
end
|
||||
else
|
||||
# Invalid flavour
|
||||
error "Invalid flavour for $argv[1]: $argv[2]"
|
||||
error "Invalid flavour for $scheme: $flavour"
|
||||
end
|
||||
end
|
||||
else
|
||||
error "Invalid scheme: $argv[1]"
|
||||
error "Invalid scheme: $scheme"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user