diff --git a/hyprlock.sh b/hyprlock.sh index 696c57a..46e2b5d 100644 --- a/hyprlock.sh +++ b/hyprlock.sh @@ -5,7 +5,8 @@ unlockedMonitorYPositions=(0 0 0) lockedMonitorYPositions=(1080 1080 1080) monitors=$(hyprctl -j monitors) -monitorIndices=$(seq 0 $(($(echo "$monitors" | jq length)-1))) +tailMonitorIndex=$(($(echo "$monitors" | jq length)-1)) +monitorIndices=$(seq 0 $tailMonitorIndex) if [ "$1" == "" ]; then monitorUnlocked=0 @@ -50,6 +51,18 @@ elif [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == exit fi +if ! [[ $1 =~ ^[0-9]+$ ]]; then + echo "Error: Invalid parameter value was provided." + echo "[monitor_id] must be an integer." + exit 1 +fi + +if [ $1 -lt 0 ] || [ $tailMonitorIndex -lt $1 ]; then + echo "Error: The provided [monitor_id] is out of range." + echo "[monitor_id] must be an integer from 0 to $tailMonitorIndex." + exit 2 +fi + monitor=$(echo "$monitors" | jq -c ".[$1]") unlockedMonitorYPosition=${unlockedMonitorYPositions[$1]}