Files

47 lines
1.0 KiB
Bash
Raw Permalink Normal View History

2025-08-18 19:53:14 -07:00
#!/usr/bin/env zsh
let just_list=0
2025-08-21 04:46:15 -07:00
local operation="--on"
2025-08-18 19:53:14 -07:00
local jq_filter_neg="| not"
local ignored=()
2025-11-27 03:12:08 -08:00
while getopts 'hldi:' name; do
2025-08-18 19:53:14 -07:00
case "${name}" in
2025-08-21 04:46:15 -07:00
h)
echo 'enable-displays-for-sleep [-l] [-d] [-i]'
echo '-d disable instead of enable'
echo '-l print the list of display that would be changed'
echo '-i ignore display'
echo 'By default, enable displays.'
;;
2025-08-18 19:53:14 -07:00
l)
just_list=1
;;
d)
jq_filter_neg=""
2025-08-21 04:46:15 -07:00
operation="--off"
2025-08-18 19:53:14 -07:00
;;
i)
ignored+="${OPTARG}"
;;
esac
done
SCRIPT=".[] | select(.enabled${jq_filter_neg}) | .name"
set -e
displays=("${(0)$(wlr-randr --json | jq --raw-output0 "${SCRIPT}")}")
set +e
displays=(${displays:|ignored})
if ((just_list)); then
printf '%s\0' ${displays}
else
2025-08-21 04:46:15 -07:00
flags=()
2025-08-18 19:53:14 -07:00
for display in ${displays}; do
2025-08-21 04:46:15 -07:00
flags+=(--output "${display}" "${operation}")
2025-08-18 19:53:14 -07:00
done
2025-08-21 04:46:15 -07:00
(( ${#flags} )) && wlr-randr ${flags}
2025-08-18 19:53:14 -07:00
fi