Streamline monitors_exist with usb_devices_exist

This commit is contained in:
dabruh 2024-04-17 18:33:43 +02:00
parent f5676e638d
commit 4cac467d32
1 changed files with 10 additions and 5 deletions

View File

@ -65,15 +65,20 @@ monitor_exist() {
# monitors_exist checks if the specified monitors are connected to the system # monitors_exist checks if the specified monitors are connected to the system
# $1..$n: The monitor names to search for # $1..$n: The monitor names to search for
monitors_exist() { monitors_exist() {
local monitor local monitor matches=0
for monitor in "$@"; do for monitor in "$@"; do
if ! monitor_exist "$monitor"; then if monitor_exist "$monitor"; then
return 1 echo "$monitor"
matches=$((matches + 1))
fi fi
done done
echo "Monitors exist: ${*}" if [ "$matches" -ne "$#" ]; then
echo "Amount of devices does not match the amount of arguments" 1>&2
return 1
fi
return 0 return 0
} }
@ -303,7 +308,7 @@ main() {
for monitor in "${monitors[@]}"; do for monitor in "${monitors[@]}"; do
IFS=',' read -r -a monitor_array <<<"$monitor" IFS=',' read -r -a monitor_array <<<"$monitor"
if monitors_exist "${monitor_array[@]}"; then if monitors_exist "${monitor_array[@]}" >/dev/null; then
echo "Applying dock profile for ${monitor_array[*]}" echo "Applying dock profile for ${monitor_array[*]}"
xrandr \ xrandr \
--output "${monitor_array[0]}" --mode 1920x1200 --rotate normal --pos 1200x1474 --primary \ --output "${monitor_array[0]}" --mode 1920x1200 --rotate normal --pos 1200x1474 --primary \