Guest User

Untitled

a guest
Jul 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # $ xrandr --version
  4. # xrandr program version 1.5.0
  5. # Server reports RandR version 1.5
  6.  
  7. # README if you want
  8. # (pretty sure no one's going to find this gist but guess there's no harm lol)
  9.  
  10. # I have 2 monitors and only wanted to toggle the rotation of only one between normal and left
  11. # executing `xrandr` will give you all of your displays and their names (also resolutions etc). mine are HDMI-1 and HDMI-2
  12.  
  13. # rotations can be: normal|left|inverted|right|x axis|y axis
  14. # last two mean the displays are mirrored in respective axes if you're into that sort of thing
  15.  
  16. # defaults. these are common for both scenarios I wanted. I always set them to make sure the values are correct
  17. xrandr --output HDMI-2 --rotate normal
  18. xrandr --output HDMI-1 --pos 1920x0
  19.  
  20. # getting HDMI-1's orientation into a variable:
  21. 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)?')
  22. # "\K" means "don't include the left part in the output string" (doesn't affect matching)
  23. # -o means take only the matching string (instead of the entire line)
  24. # with this regex, $orientation is left/others or empty string for normal.
  25.  
  26. # regex for matching everything in the line:
  27. # (.+) (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)?
  28.  
  29. # toggle HDMI-1's rotation and vertically center HDMI-2 to HDMI-1
  30. if [ $orientation == "left" ]; then
  31. xrandr --output HDMI-1 --rotate normal
  32. xrandr --output HDMI-2 --pos 0x0
  33. else
  34. xrandr --output HDMI-1 --rotate left
  35. xrandr --output HDMI-2 --pos 0x420
  36. fi
Add Comment
Please, Sign In to add comment