Skip to content

Instantly share code, notes, and snippets.

@jeroenvanwijgerden
Created March 15, 2024 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvanwijgerden/26f5d8ef665f622d8f2ea5c87a77791d to your computer and use it in GitHub Desktop.
Save jeroenvanwijgerden/26f5d8ef665f622d8f2ea5c87a77791d to your computer and use it in GitHub Desktop.
Monitors
#!/bin/bash
# Turn off all monitors other than DP0
xrandr --output DisplayPort-0 --auto --primary --output DisplayPort-1 --off --output DisplayPort-2 --off --output HDMI-A-0 --off
# Check if the command argument is provided
if [ $# -eq 0 ]; then
exit 0
fi
# Get the command arguments
arguments=$@
# Set a variable to true if '1' appears in the arguments list
found_1=false
for arg in $arguments; do
if [ "$arg" = "1" ]; then
found_1=true
break
fi
done
# Perform actions based on the command arguments
for arg in $arguments; do
if [ "$arg" = "1" ]; then
# Turn on DisplayPort-1, left of DP0
xrandr --output DisplayPort-1 --auto --left-of DisplayPort-0
elif [ "$arg" = "2" ]; then
# Turn on HDMI-A-0, right of DP0
xrandr --output HDMI-A-0 --auto --right-of DisplayPort-0
elif [ "$arg" = "3" ]; then
# Turn on DisplayPort-2
xrandr --output DisplayPort-2 --auto --below DisplayPort-0
if [ "$found_1" = true ]; then
# Invoke additional command for found_1
xrandr --output DisplayPort-2 --pos 3640x1440
else
# Invoke additional command for not found_1
xrandr --output DisplayPort-2 --pos 1080x1440
fi
else
# Invalid argument
echo "Invalid argument: $arg. Please use '1', '2', or '3'"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment