1
1
Fork 0

zoom: fix regex matching

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2024-09-27 15:11:57 -05:00
parent 20cd92006e
commit c697d8dd77
Signed by: myned
GPG key ID: C7224454F7881A34

View file

@ -4,19 +4,25 @@
#
# https://github.com/sigoden/argc
# @arg factor=1 Absolute or relative factor to zoom to, empty to reset
# @arg factor=1.0 Absolute or relative factor to zoom to, empty to reset
eval "$(argc --argc-eval "$0" "$@")"
factor="$(hyprctl -j getoption cursor:zoom_factor | jq -r .float)" # Current factor
if [[ "${argc_factor:-}" =~ ^[+|-][1-9]\.*[0-9]*$ ]]; then
# Match regex for zero-padded decimals
if [[ "${argc_factor:-}" =~ ^[+|-][0-9]\.[0-9]+$ ]]; then
factor="$(bc <<< "$factor ${argc_factor}")"
elif [[ "${argc_factor:-}" =~ ^[1-9]\.*[0-9]*$ ]]; then
elif [[ "${argc_factor:-}" =~ ^[0-9]\.[0-9]+$ ]]; then
factor="${argc_factor:-}"
else
echo "Factor must be an absolute or relative decimal between 1 and 9"
echo "Factor must be an absolute or relative decimal between 1.0 and 9.9"
exit 1
fi
# Reset if outside range
if (("$(bc <<< "$factor < 1")")); then
factor=1.0
fi
hyprctl keyword cursor:zoom_factor "$factor"