dotfiles-x1177210a4
improve envyswitch script
+11 −15
1 file changed
- M .config/waybar/scripts/envyswitch.sh +11 −15
| @@ -1,21 +1,17 @@ | |||
| 1 | 1 | #!/bin/env bash | |
| 2 | 2 | ||
| 3 | 3 | mode="$(printf "Integrated\nHybrid\nNvidia" | rofi -dmenu -case-smart -matching "fuzzy" -p "Select the graphics mode:")" | |
| 4 | − | printf $mode | |
| 5 | 4 | ||
| 5 | + | # Exit if no selection was made | |
| 6 | + | [ -z "$mode" ] && exit 1 | |
| 6 | 7 | ||
| 7 | − | case "$mode" in | |
| 8 | − | Integrated) | |
| 9 | − | sudo -A envycontrol -s integrated && notify-send "Graphics mode set to integrated" | |
| 10 | − | ;; | |
| 11 | − | Hybrid) | |
| 12 | − | sudo -A envcontrol -s hybrid && notify-send "Graphics mode set to hybrid" | |
| 13 | − | ;; | |
| 14 | − | Nvidia) | |
| 15 | − | sudo -A envycontrol -s nvidia && notify-send "Graphics mode set to nvidia" | |
| 16 | − | ;; | |
| 17 | − | *) | |
| 18 | − | exit 1 | |
| 19 | − | ;; | |
| 20 | − | esac | |
| 8 | + | notify-send "Switching to $mode mode..." | |
| 21 | 9 | ||
| 10 | + | # Map mode to envycontrol argument | |
| 11 | + | arg=$(echo "$mode" | tr '[:upper:]' '[:lower:]') | |
| 12 | + | ||
| 13 | + | if sudo -A envycontrol -s "$arg"; then | |
| 14 | + | notify-send "Graphics mode set to $mode" | |
| 15 | + | else | |
| 16 | + | notify-send "Failed to set graphics mode to $mode" | |
| 17 | + | fi | |