♻️ eww(scripts/eww-window): separate actions into functions
This commit is contained in:
+48
-22
@@ -1,18 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# arg1,$1 should be one of the options listed in help command;
|
||||
# arg2,$2 should be the literal window name as defined in eww configuration.
|
||||
# arg1($1) should be one of the options listed in help command;
|
||||
# arg2($2) should be the literal window name as defined in eww configuration.
|
||||
|
||||
check_if_empty() {
|
||||
if [[ -z $1 ]]; then
|
||||
echo "[error] argument $2 is empty!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--help | -h | help | h)
|
||||
printf \
|
||||
function help_message() {
|
||||
printf \
|
||||
"This is a helper script that helps opening/closing eww windows on
|
||||
retrozinndev's Hyprland Dots, by checking if the window is already
|
||||
open/closed before doing anything, also changes eww state variables.
|
||||
@@ -40,6 +32,45 @@ Options:
|
||||
Developer: retrozinndev (João Dias), https://github.com/retrozinndev
|
||||
Issue tracker: https://github.com/retrozinndev/Hyprland-Dots/issues
|
||||
Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
||||
}
|
||||
|
||||
function send_log() {
|
||||
case "$1" in
|
||||
err*)
|
||||
tag_color="\e[31m"
|
||||
;;
|
||||
warn*)
|
||||
tag_color="\e[33m"
|
||||
;;
|
||||
*)
|
||||
tag_color="\e[34m"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "[$tag_color$1\e[0m] $2"
|
||||
}
|
||||
|
||||
function check_if_empty() {
|
||||
if [[ $1 == "" ]]; then
|
||||
send_log "error" "argument \$1 is empty!"
|
||||
help_message
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function toggle_eww_window() {
|
||||
if ! [[ $(eww active-windows) =~ "$1" ]]; then
|
||||
eww open "$1"
|
||||
eww update "window_state_$1=open"
|
||||
else
|
||||
eww close "$1"
|
||||
eww update "window_state_$1=closed"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--help | -h | help | h)
|
||||
help_message
|
||||
;;
|
||||
|
||||
--open | open)
|
||||
@@ -48,7 +79,7 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
||||
eww open "$2"
|
||||
eww update "window_state_$2=open"
|
||||
else
|
||||
echo "[info] Window '$2' is already open, ignored."
|
||||
send_log "info" "Window '$2' is already open, ignored."
|
||||
fi
|
||||
;;
|
||||
|
||||
@@ -58,21 +89,16 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
||||
eww close "$2"
|
||||
eww update "window_state_$2=closed"
|
||||
else
|
||||
echo "[info] Window '$2' is already closed, ignored."
|
||||
send_log "info" "Window '$2' is already closed, ignored."
|
||||
fi
|
||||
;;
|
||||
|
||||
--toggle | toggle)
|
||||
check_if_empty $2 "WINDOW_NAME"
|
||||
if ! [[ $(eww active-windows) =~ "$2" ]]; then
|
||||
eww open "$2"
|
||||
eww update "window_state_$2=open"
|
||||
else
|
||||
eww close "$2"
|
||||
eww update "window_state_$2=closed"
|
||||
fi
|
||||
toggle_eww_window $2
|
||||
;;
|
||||
*)
|
||||
echo "[error] Action not specified or incorrect command order. Good example: \`./eww-window.sh open bar\`"
|
||||
send_log "error" "Action not specified or incorrect command order. Good example: \`./eww-window.sh open bar\`"
|
||||
help_message
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user