configure_nvidia_optimus.sh 709 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # fail if any commands fails
  3. set -e
  4. # debug log
  5. #set -x
  6. # Set superuser privileges command if not set
  7. if [[ -z $su ]]; then
  8. export su="sudo"
  9. fi
  10. $su pacman -S nvidia nvidia-utils xorg-xrandr
  11. paru -S envycontrol
  12. options=(integrated hybrid nvidia)
  13. read -rp "Set nvidia optimus configuration: (integrated|hybrid|nvidia)" option
  14. while [[ " "${options[@]}" " != *" $option "* ]]; do
  15. echo "$option: not recognized. Valid options are:"
  16. echo "${options[@]/%/,}"
  17. read -rp "?: (y|n)" option
  18. done
  19. case "$option" in
  20. *integrated*)
  21. $su envycontrol --switch integrated
  22. ;;
  23. *hybrid*)
  24. $su envycontrol --switch hybrid
  25. ;;
  26. *nvidia*)
  27. $su envycontrol --switch nvidia
  28. ;;
  29. esac
  30. $su