Can I automatically generate a command-line for xrandr based on the current set-up?

I wrote a set-up script for my dual screen set-up some while ago, for when X went bonkers and I needed to restore sanity, but I just found a spare monitor and worked out I can use DP from a USB-C port I didn't know I had.

It suddenly occurred to me that xrandr might be able to create its own command-line for the current set-up, rather than me having to fiddle about writing it myself, but I can't find any options for that.

Is there a utility for this? Is it a stupid idea?


I've had the same problem before which led me to create a function in ~/.bashrc called xreset:

xreset () {

    xrandr --output HDMI-0  --mode 1920x1080 --pos 0x0       --rotate normal \
           --output eDP-1-1 --mode 1920x1080 --pos 3840x2160 --rotate normal \
           --output DP-1-1  --mode 3840x2160 --pos 1920x0    --rotate normal

} # xreset

After you get your monitors arranged by position and resolution, grab the current setup with:

$ xrandr | grep " connected"

HDMI-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 1107mm x 623mm
eDP-1-1 connected primary 1920x1080+3840+2160 (normal left inverted right x axis y axis) 382mm x 215mm
DP-1-1 connected 3840x2160+1920+0 (normal left inverted right x axis y axis) 1600mm x 900mm

All the information is there for you to create your own xreset function.


Tut. Sometimes asking the question gets you different search terms.

Arandr is a graphical editor that allows you to move things around, but most pertinently it will save/export xrandr command-lines as scripts:

xrandr \
   --output HDMI-2 --mode 3840x2160 --pos 0x48 --rotate normal \
   --output HDMI-1 --off \
   --output DP-1 --mode 3840x2160 --pos 5760x0 --rotate left \
   --output eDP-1 --primary --mode 1920x1080 --pos 3840x1528 --rotate normal \
   --output DP-2 --off

I don't need the 'off' outputs, but they're harmless.