Skip to content

Instantly share code, notes, and snippets.

@DeFiYaco
Last active October 6, 2020 12:17
Show Gist options
  • Save DeFiYaco/56a4d5fcbe6e646c6a88dd0647d615e5 to your computer and use it in GitHub Desktop.
Save DeFiYaco/56a4d5fcbe6e646c6a88dd0647d615e5 to your computer and use it in GitHub Desktop.
Nvidia Optimus switcher
#!/bin/bash
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "Not running as root"
exit
fi
if [ "$1" == "intel" ]
then
mv /etc/X11/xorg.conf.d/20-intel /etc/X11/xorg.conf.d/20-intel.conf
prime-select intel
elif [ "$1" == "nvidia" ]
then
mv /etc/X11/xorg.conf.d/20-intel.conf /etc/X11/xorg.conf.d/20-intel
prime-select nvidia
else
echo "You should pass either intel or nvidia as an argument"
fi
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "TearFree" "true"
EndSection

Small bash script that automatically disables/enables intel xorg.conf upon switching to nvidia/intel gpu . This is needed for all owners of nvidia optimus machines that want to have custom config for intel driver like for example TearFree.

Requirements:

  • sudo
  • nvidia optimus hardware
  • nvidia-390 driver or newer with prime-select installed

How to use:

  • Place 20-intel-conf in /etc/X11/xorg.conf.d/
  • Place 1-prime-select in /usr/local/bin
  • Run sudo chmod +x 1-prime-select
  • Switch gpu by running sudo 1-prime-select intel or sudo 1-prime-select nvidia
  • Logout or reboot for changes to take effect

Notes:

This intel configuration file is just an example that I use because without it I get horrible screen tearing. Feel free to modify it to your needs.
Intel config file breaks nvidia driver if it stays enabled so this script just removes .conf extension so that xorg.conf does not recognize it as module to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment