Linux: dump NVIDIA card settingsΒΆ

This is an experimental script that tries to dump the current monitors configuration for nvidia video cards on Linux.

What it does, is to print a script to be used to restore the current video metamode, and set appropriate screen resolution using xrandr. It is untested with complex configurations, involving xinerama and more than two active monitors at once.

Some ideas come from http://ubuntuforums.org/showthread.php?t=1558492

#!/bin/bash

##----------------------------------------------------------------------
## Tries to dump settings for nvidia video cards.
##
## WARNING! this is experimental software - USE AT YOUR ONW RISK
##
## Author: Samuele ~redShadow~ Santi <[email protected]>
## License: Under GPL v2 or newer
##----------------------------------------------------------------------

if ! which nv-control-dpy &>/dev/null; then
    echo "nv-control-dpy is required, but was not found!"
    echo "This is usually contained in the 'nvidia-settings' package."
    exit 1
fi

if ! which xrandr &>/dev/null; then
    echo "xrandr is required, but was not found!"
    echo "This is usually contained in the 'x11-xserver-utils' package."
    exit 1
fi

echo '#!/bin/sh'
echo "## Autogenerated on $( date +'%F %H:%M' )"
echo 'nv-control-dpy --set-associated-dpys '"$( nv-control-dpy --get-associated-dpys | grep "^associated display device mask:" | sed "s/.*:\s*//" )"
echo 'nv-control-dpy --add-metamode "'"$( nv-control-dpy --print-current-metamode | grep "^current metamode:" | sed 's/.*".*::\s*\(.*\)"/\1/' )"'"'
xrandr 2>/dev/null | grep "^\s\+\([0-9]\+x[0-9]\+\)\(\s\+[0-9]\+\.[0-9]\+\)\+\*\s*\$" | sed "s/^\s\+\([0-9]\+x[0-9]\+\)\(\s\+\([0-9]\+\.[0-9]\+\)\)\+\*\s*\$/xrandr -s \1 -r \3/"

Usually, the generated output will look like this:

#!/bin/sh
## Autogenerated on 2012-04-23 13:11
nv-control-dpy --set-associated-dpys 0x000d0000
nv-control-dpy --add-metamode "DFP-2: 1920x1200 @1920x1200 +1920+0, DFP-3: nvidia-auto-select @1920x1200 +0+0, DFP-0: NULL"
xrandr -s 3840x1200 -r 51.0
comments powered by Disqus

Previous topic

Linux: Resizing a LUKS volume on LVM

Next topic

Linux: printing manpages

This Page