Add zsh completions

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-10 16:35:58 +00:00
parent 465198f3c8
commit d967d5d603
9 changed files with 101 additions and 126 deletions

View File

@@ -23,7 +23,7 @@ in
wayland.windowManager.hyprland.settings.bind = [
"Ctrl_Alt, r, exec, ${themeBin}"
"Ctrl_Alt, t, exec, ${themeBin} toggle"
"Ctrl_Alt, t, exec, ${themeBin} -m toggle"
];
};
}

View File

@@ -532,5 +532,7 @@ in
}) cfg.template;
}
);
programs.zsh.initExtra = builtins.readFile ./theme.completion.sh;
};
}

View File

@@ -0,0 +1,11 @@
_theme-completion() {
local options=(
'-m[set mode: light, dark, or toggle]:mode:(light dark toggle)'
'-w[set wallpaper: specify file path]:file:_files'
)
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -s $options
}
compdef _theme-completion theme

View File

@@ -10,15 +10,6 @@ set_wallpaper() {
fi
}
set_mode() {
if [[ "$1" = "light" ]] || [[ "$1" = "dark" ]]; then
MODE="$1"
else
echo "Invalid mode: $1. Use 'light' or 'dark'."
exit 1
fi
}
toggle_mode() {
if [[ "$(cat "${CONFIG}"/mode)" = "light" ]]; then
MODE="dark"
@@ -28,7 +19,7 @@ toggle_mode() {
}
show_usage() {
echo "Usage: theme {toggle|light|dark|mode <mode>|wallpaper <file> [mode]}"
echo "Usage: theme [-m {light|dark|toggle}] [-w <file>]"
}
finish() {
@@ -39,56 +30,31 @@ finish() {
"${RELOAD}" > /dev/null
}
if [[ $# -eq 0 ]]; then
finish
else
case "$1" in
toggle)
if [[ $# -eq 1 ]]; then
toggle_mode
else
show_usage
exit 1
fi
# Parse arguments
while getopts "m:w:" opt; do
case "$opt" in
m)
case "$OPTARG" in
light|dark)
MODE="$OPTARG"
;;
toggle)
toggle_mode
;;
*)
show_usage
exit 1
;;
esac
;;
light)
if [[ $# -eq 1 ]]; then
set_mode "light"
else
show_usage
exit 1
fi
;;
dark)
if [[ $# -eq 1 ]]; then
set_mode "dark"
else
show_usage
exit 1
fi
;;
mode)
if [[ $# -eq 2 ]]; then
set_mode "$2"
else
show_usage
exit 1
fi
;;
wallpaper)
if [[ $# -ge 2 ]] && [[ $# -le 3 ]]; then
set_wallpaper "$2"
[[ $# -eq 3 ]] && set_mode "$3"
else
show_usage
exit 1
fi
w)
set_wallpaper "$OPTARG"
;;
*)
show_usage
exit 1
;;
esac
done
finish
fi
finish