-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard
executable file
·75 lines (69 loc) · 1.96 KB
/
card
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
function gpu_on {
echo 'Enabling NVIDIA GPU'
sudo tee /proc/acpi/bbswitch <<< ON
echo 'Loading nvidia module'
sudo modprobe nvidia
echo 'Loading nvidia_drm module'
sudo modprobe nvidia_drm
echo -n 'Current state of NVIDIA GPU: '
cat /proc/acpi/bbswitch
}
function gpu_off {
echo 'Unloading nvidia_drm module'
sudo rmmod nvidia_drm
echo 'Unloading nvidia_modeset module'
sudo rmmod nvidia_modeset
echo 'Unloading nvidia_uvm module'
sudo rmmod nvidia_uvm
echo 'Unloading nvidia module'
sudo rmmod nvidia
echo 'Disabling NVIDIA GPU'
sudo tee /proc/acpi/bbswitch <<< OFF
echo -n 'Current state of NVIDIA GPU: '
cat /proc/acpi/bbswitch
}
function gpu_stat {
echo -n 'Current state of NVIDIA GPU: '
cat /proc/acpi/bbswitch
nvidia-smi
}
function ext_display {
echo 'You can now plug in your external display'
intel-virtual-output -f
}
function helpmsg {
echo "Discrete NVIDIA graphics card switcher"
echo "Usage: "
echo " card [options/app]"
echo "Options: "
echo " on Turn the discrete graphics card ON"
echo " off Turn the discrete graphics card OFF"
echo " run Turn the card on and turn it off after keyboard interruption"
echo " stat Show graphics card status"
echo " watch Monitor graphics card status"
echo " display Start external display (requires intel-virtual-output)"
echo " [app] Run command using optirun (requires bumblebee)"
}
if [ -n "$1" ]; then
if [ "$1" = "on" ] ;then
gpu_on
elif [ "$1" = "off" ]; then
gpu_off
elif [ "$1" = "run" ]; then
gpu_on
watch -n 2 card stat
gpu_off
elif [ "$1" = "stat" ]; then
gpu_stat
elif [ "$1" = "watch" ]; then
watch -n 2 card stat
elif [ "$1" = "display" ]; then
ext_display
else
echo "Running command: optirun $1"
eval "optirun $1"
fi
else
helpmsg
fi