Last active
January 15, 2021 04:06
-
-
Save jmatthewturner/0a224a9e906a14e19b9230da8e17295b to your computer and use it in GitHub Desktop.
Bash Script for Switching Graphics Modes on System 76 Oryx Pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is a script for switching between Intel and NVIDIA graphics modes | |
# on System 76 Oryx Pros. It was written because I installed KDE Plasma, | |
# thereby losing the graphics-switching functionality built into Gnome. | |
# But it should work just fine under Gnome, as well, if you're into that. | |
# | |
# It uses a modified version of Dave Miller's excellent ask.sh script, | |
# which can be found here: | |
# https://gist.github.com/davejamesmiller/1965569 | |
# | |
# To modify ask.sh, simply change line 23 to read | |
# echo -n -e "$1 [$prompt] " | |
# | |
# (Adding the -e flag enables support for escape sequences, which allows | |
# the colored text formatting.) | |
# | |
# It also uses my own colors.sh script, which defines a list of colors | |
# for text formatting: | |
# https://gist.github.com/jmatthewturner/2aeee120aa112fd51b000e13579c2654 | |
# | |
# Written by jmatthewturner | |
# https://github.com/jmatthewturner | |
# https://www.youtube.com/jmatthewturner/ | |
# | |
# https://gist.github.com/jmatthewturner/0a224a9e906a14e19b9230da8e17295b | |
# | |
source ~/Scripts/ask.sh # https://gist.github.com/davejamesmiller/1965569 | |
source ~/Scripts/colors.sh # https://gist.github.com/jmatthewturner/2aeee120aa112fd51b000e13579c2654 | |
# Restart the machine after the graphics have been updated. | |
# | |
function restart() | |
{ | |
if ask "You need to restart for the change to take effect. Would you like to restart now?" N | |
then | |
echo "Restarting..." | |
sudo shutdown -r now | |
else | |
echo -e "${new_color}$new_mode_formatted ${RESET}graphics will take effect upon next restart." | |
echo | |
fi | |
} | |
# Switch from current graphics mode to new graphics mode. | |
# | |
function switch() | |
{ | |
if ask "Would you like to switch to ${new_color}$new_mode_formatted ${RESET}graphics?" Y | |
then | |
system76-power graphics $new_mode | |
echo | |
echo 'Done.' | |
echo | |
restart | |
else | |
echo | |
echo "Well ok, then." | |
echo | |
fi | |
} | |
# BEGIN MAIN ROUTINE | |
# | |
# Establish which graphics mode we are currently in and define colors for later formatting. | |
# | |
current_mode=$( system76-power graphics ) # Get current graphics mode. | |
if [ $current_mode == 'intel' ] | |
then | |
current_mode_formatted=Intel # Current graphics mode for formatted output. | |
current_color=$LIGHTBLUE # Used to format Intel as light blue. | |
new_color=$LIGHTYELLOW # Used to format NVIDIA as light yellow. | |
new_mode=nvidia # Define new mode. | |
new_mode_formatted=NVIDIA # Define new mode for formatted output. | |
elif [ $current_mode == 'nvidia' ] | |
then | |
current_mode_formatted=NVIDIA # Current graphics mode for fomatted output. | |
current_color=$LIGHTYELLOW # Used to format NVIDIA as light yellow. | |
new_color=$LIGHTBLUE # Used to format Intel as light blue. | |
new_mode=intel # Define new mode. | |
new_mode_formatted=Intel # Define new mode for formatted output. | |
else | |
echo "${GREEN}There is a glitch in the Matrix.${RESET}" | |
fi | |
# Report the current graphics mode and call the switch() function to make the switch. | |
# | |
echo | |
echo -e "You are currently using ${current_color}${current_mode_formatted} ${RESET}graphics." | |
switch | |
# Exit successfully. | |
# | |
exit 0 | |
# Written by jmatthewturner | |
# https://github.com/jmatthewturner | |
# https://www.youtube.com/jmatthewturner/ | |
# | |
# https://gist.github.com/jmatthewturner/0a224a9e906a14e19b9230da8e17295b | |
# |
Thanks for this, I just got a new Oryx Pro 6 and was debating on whether I should move to KDE Plasma, which I'm currently using on my old Dell, but wondered what I was going to lose, like graphics switching.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my first Bash script, so if I did anything stupid, please let me know!