♻️ eww(scripts/eww-window): separate actions into functions
This commit is contained in:
+47
-21
@@ -1,17 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# arg1,$1 should be one of the options listed in help command;
|
# 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.
|
# arg2($2) should be the literal window name as defined in eww configuration.
|
||||||
|
|
||||||
check_if_empty() {
|
function help_message() {
|
||||||
if [[ -z $1 ]]; then
|
|
||||||
echo "[error] argument $2 is empty!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
--help | -h | help | h)
|
|
||||||
printf \
|
printf \
|
||||||
"This is a helper script that helps opening/closing eww windows on
|
"This is a helper script that helps opening/closing eww windows on
|
||||||
retrozinndev's Hyprland Dots, by checking if the window is already
|
retrozinndev's Hyprland Dots, by checking if the window is already
|
||||||
@@ -40,6 +32,45 @@ Options:
|
|||||||
Developer: retrozinndev (João Dias), https://github.com/retrozinndev
|
Developer: retrozinndev (João Dias), https://github.com/retrozinndev
|
||||||
Issue tracker: https://github.com/retrozinndev/Hyprland-Dots/issues
|
Issue tracker: https://github.com/retrozinndev/Hyprland-Dots/issues
|
||||||
Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
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)
|
--open | open)
|
||||||
@@ -48,7 +79,7 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
|||||||
eww open "$2"
|
eww open "$2"
|
||||||
eww update "window_state_$2=open"
|
eww update "window_state_$2=open"
|
||||||
else
|
else
|
||||||
echo "[info] Window '$2' is already open, ignored."
|
send_log "info" "Window '$2' is already open, ignored."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -58,21 +89,16 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo."
|
|||||||
eww close "$2"
|
eww close "$2"
|
||||||
eww update "window_state_$2=closed"
|
eww update "window_state_$2=closed"
|
||||||
else
|
else
|
||||||
echo "[info] Window '$2' is already closed, ignored."
|
send_log "info" "Window '$2' is already closed, ignored."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--toggle | toggle)
|
--toggle | toggle)
|
||||||
check_if_empty $2 "WINDOW_NAME"
|
check_if_empty $2 "WINDOW_NAME"
|
||||||
if ! [[ $(eww active-windows) =~ "$2" ]]; then
|
toggle_eww_window $2
|
||||||
eww open "$2"
|
|
||||||
eww update "window_state_$2=open"
|
|
||||||
else
|
|
||||||
eww close "$2"
|
|
||||||
eww update "window_state_$2=closed"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
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
|
esac
|
||||||
|
|||||||
@@ -84,24 +84,24 @@ button label {
|
|||||||
menu {
|
menu {
|
||||||
background: $background;
|
background: $background;
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
padding: 3px;
|
padding: 2px;
|
||||||
|
|
||||||
& > menuitem {
|
& > menuitem {
|
||||||
padding: 8px 24px;
|
padding: 8px 24px;
|
||||||
border-radius: 5px;
|
border-radius: 4px;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: $color1;
|
background: $color1;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:first-child {
|
&:first-child {
|
||||||
border-top-left-radius: inherit;
|
border-top-left-radius: 12px;
|
||||||
border-top-right-radius: inherit;
|
border-top-right-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
border-bottom-left-radius: inherit;
|
border-bottom-left-radius: 12px;
|
||||||
border-bottom-right-radius: inherit;
|
border-bottom-right-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
|
|||||||
Reference in New Issue
Block a user