This commit is contained in:
tavo-wasd 2024-08-25 14:58:40 -06:00
parent 3d8dde18b4
commit 7f7ae297d9

View file

@ -1,31 +1,24 @@
#!/bin/sh #!/bin/sh
LIST="$(xrandr | sed '/ connected/!d;s/ .*$//')" LIST="$(xrandr | sed '/ connected/!d;s/ .*$//')"
ULIST="$(xrandr | sed '/ disconnected/!d;s/ .*$//')" ULIST="$(xrandr | sed '/ disconnected/!d;s/ .*$//')"
MONITORS="$(printf '%s' "${LIST}" | tr '\n' ' ')" MONITORS="$(printf '%s' "${LIST}" | tr '\n' ' ')"
MIRR="$(printf 'Yes\nNo' | menu "Mirror monitors?:")"
for i in ${ULIST} ; do for i in ${ULIST} ; do
UNSET="${UNSET} --output ${i} --off" UNSET="${UNSET} --output ${i} --off"
done done
[ "${MIRR}" = "Yes" ] && CMD="$(FIRST=1 ; for i in ${MONITORS} ; do CMD="$(FIRST=1 ; for i in ${MONITORS} ; do
CURR="${i}" # shellcheck disable=SC2030
[ -z "${CURR}" ] && exit 1
[ "${FIRST}" ] && printf 'xrandr --output %s' "${CURR}" && FIRST=
[ "${LAST}" ] && printf ' --same-as %s' "${CURR}"
LAST="${CURR}"
done)"
! [ "${CMD}" ] && CMD="$(FIRST=1 ; for i in ${MONITORS} ; do
CURR="$(printf '%s' "${LIST}" | sed "/${LAST:=empty}/d" | menu "Next monitor (to right):")" CURR="$(printf '%s' "${LIST}" | sed "/${LAST:=empty}/d" | menu "Next monitor (to right):")"
[ -z "${CURR}" ] && exit 1 [ -z "${CURR}" ] && exit 1
[ "${FIRST}" ] && printf 'xrandr --output %s' "${CURR}" && FIRST= [ "${FIRST}" ] && printf 'xrandr --output %s' "${CURR}" && FIRST=
# shellcheck disable=SC2031
[ "${LAST}" ] && printf ' --left-of %s' "${CURR}" [ "${LAST}" ] && printf ' --left-of %s' "${CURR}"
LAST="${CURR}" LAST="${CURR}"
done)" done)"
! [ "${MIRR}" = "Yes" ] && for i in ${MONITORS} ; do for i in ${MONITORS} ; do
case ${CMD} in case ${CMD} in
*${i}*) ;; *${i}*) ;;
*) UNSET="${UNSET} --output ${i} --off" *) UNSET="${UNSET} --output ${i} --off"