Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # $ xrandr --version
- # xrandr program version 1.5.0
- # Server reports RandR version 1.5
- # README if you want
- # (pretty sure no one's going to find this gist but guess there's no harm lol)
- # I have 2 monitors and only wanted to toggle the rotation of only one between normal and left
- # executing `xrandr` will give you all of your displays and their names (also resolutions etc). mine are HDMI-1 and HDMI-2
- # rotations can be: normal|left|inverted|right|x axis|y axis
- # last two mean the displays are mirrored in respective axes if you're into that sort of thing
- # defaults. these are common for both scenarios I wanted. I always set them to make sure the values are correct
- xrandr --output HDMI-2 --rotate normal
- xrandr --output HDMI-1 --pos 1920x0
- # getting HDMI-1's orientation into a variable:
- orientation=$(xrandr | grep -o -P 'HDMI-1 .+ (\d{4}x\d{4}\+\d{1,4}\+\d{1,4}) \K(left|inverted|right|x axis|y axis)?')
- # "\K" means "don't include the left part in the output string" (doesn't affect matching)
- # -o means take only the matching string (instead of the entire line)
- # with this regex, $orientation is left/others or empty string for normal.
- # regex for matching everything in the line:
- # (.+) (connected|disconnected)( primary)?(?: ([0-9]{1,5}x[0-9]{1,5})\+([0-9]{1,5})\+([0-9]{1,5}))?( left| inverted| right| x axis| y axis)? \(normal left inverted right x axis y axis\)( \d+mm x \d+mm)?
- # toggle HDMI-1's rotation and vertically center HDMI-2 to HDMI-1
- if [ $orientation == "left" ]; then
- xrandr --output HDMI-1 --rotate normal
- xrandr --output HDMI-2 --pos 0x0
- else
- xrandr --output HDMI-1 --rotate left
- xrandr --output HDMI-2 --pos 0x420
- fi
Add Comment
Please, Sign In to add comment