Skip to content

Instantly share code, notes, and snippets.

@bradfordcp
Created May 18, 2020 18:22
Show Gist options
  • Save bradfordcp/925817863ee731459a656ef1f5bc9f6c to your computer and use it in GitHub Desktop.
Save bradfordcp/925817863ee731459a656ef1f5bc9f6c to your computer and use it in GitHub Desktop.
gswitch
#! /bin/env fish
set NVIDIA_GPU_COUNT (/usr/sbin/lspci | grep -i nvidia | wc -l)
if test "$NVIDIA_GPU_COUNT" -gt 1
echo "Setting graphics to eGPU"
/usr/local/bin/gswitch egpu
else
echo "Setting graphics to Intel"
/usr/local/bin/gswitch internal-intel
end
[Unit]
Description=Automatic detection of hardware and XOrg config
[Service]
Type=oneshot
ExecStart=/usr/local/bin/gautodetect
[Install]
WantedBy=local-fs.target
#!/bin/env fish
if test (whoami) != "root"
echo "You need to be root."
exit
end
set LINK_TARGET /etc/X11/xorg.conf
set INTERNAL_INTEL_XORG_CONF /etc/X11/xorg.internal.intel.conf
set INTERNAL_NVIDIA_XORG_CONF /etc/X11/xorg.internal.nvidia.conf
set EGPU_NVIDIA_XORG_CONF /etc/X11/xorg.egpu.nvidia.conf
switch (echo $argv[1])
case "egpu"
rm -f $LINK_TARGET
ln -s $EGPU_NVIDIA_XORG_CONF $LINK_TARGET
case "internal-intel"
rm -f $LINK_TARGET
ln -s $INTERNAL_INTEL_XORG_CONF $LINK_TARGET
case "internal-nvidia"
rm -f $LINK_TARGET
ln -s $INTERNAL_NVIDIA_XORG_CONF $LINK_TARGET
case "*"
echo "Unknown configuration $argv[1]. Valid options are 'egpu', 'internal-intel', 'internal-nvidia'"
exit 1
end
exit 0
Section "Module"
Load "modesetting"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
BusID "PCI:7:0:0"
Option "AllowEmptyInitialConfiguration"
Option "AllowExternalGpus" "True"
EndSection
Section "Monitor"
Identifier "HDMI-0"
Option "Primary" "true"
EndSection
Section "Monitor"
Identifier "eDP-1-1"
Option "LeftOf" "HDMI-0"
EndSection
# Intentionally empty
Section "Module"
Load "modesetting"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
BusID "PCI:1:0:0"
Option "AllowEmptyInitialConfiguration"
EndSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment