Skip to content

Commit ec469b5

Browse files
committed
chore: add comments, add error validation
1 parent aaf70d2 commit ec469b5

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

dotfiles/.config/ml4w/scripts/ml4w-sidepad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ if [ -f "$SIDEPAD_POS_FILE" ]; then
2626
else
2727
SIDEPAD_POS="left"
2828
fi
29-
source $SIDEPAD_PADS_FOLDER/$(cat "$SIDEPAD_DATA")
3029
source $SIDEPAD_PADS_FOLDER/$SIDEPAD_ACTIVE
3130
echo ":: Current sidepad: $SIDEPAD_ACTIVE"
3231
echo ":: Current sidepad app: $SIDEPAD_APP"
@@ -65,8 +64,10 @@ if [[ "$1" == "--init" ]]; then
6564
eval "$SIDEPAD_PATH --position '$SIDEPAD_POS' --class '$SIDEPAD_CLASS' --init '$SIDEPAD_APP'"
6665
elif [[ "$1" == "--hide" ]]; then
6766
if [[ "$SIDEPAD_POS" == "left" ]]; then
67+
# Hide left sidepad
6868
eval "$SIDEPAD_PATH --position '$SIDEPAD_POS' --class '$SIDEPAD_CLASS' --hide"
6969
else
70+
# Show right sidepad
7071
eval "$SIDEPAD_PATH --position '$SIDEPAD_POS' --class '$SIDEPAD_CLASS' $SIDEPAD_OPTIONS"
7172
fi
7273
elif [[ "$1" == "--test" ]]; then

dotfiles/.config/sidepad/sidepad

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ while [[ $# -gt 0 ]]; do
9292
;;
9393

9494
--position)
95+
if [[ "$2" != "left" && "$2" != "right" ]]; then
96+
echo "Error: --position must be either 'left' or 'right' (got '$2')." >&2
97+
exit 1
98+
fi
9599
POSITION="$2"
96100
shift; shift
97101
;;
@@ -213,7 +217,10 @@ if [[ "$HIDE_REQUESTED" -eq 1 ]]; then
213217
# Restore focus
214218
if [ -f "$PREV_FOCUS_FILE" ]; then
215219
PREV_FOCUS=$(cat "$PREV_FOCUS_FILE")
216-
hyprctl dispatch focuswindow address:$PREV_FOCUS
220+
if [[ -n "$PREV_FOCUS" ]]; then
221+
# Suppress errors in case the previous window no longer exists or the address is invalid
222+
hyprctl dispatch focuswindow address:"$PREV_FOCUS" 2>/dev/null || true
223+
fi
217224
rm "$PREV_FOCUS_FILE"
218225
fi
219226

0 commit comments

Comments
 (0)