Skip to content

Instantly share code, notes, and snippets.

@brunomiguel
Created May 22, 2025 22:05
Show Gist options
  • Save brunomiguel/23fdfc167fb2e3444010dafea3566639 to your computer and use it in GitHub Desktop.
Save brunomiguel/23fdfc167fb2e3444010dafea3566639 to your computer and use it in GitHub Desktop.
function cputurbo() {
# CHECK IF THE NOFITY-SEND BINARY EXISTS IN THE SYSTEM
# AND ALERT THE USER IF IT DOESN'T
if ! command -v notify-send &> /dev/null; then
echo -e "\nWarning: notify-send could not be found.\
\nPlease install it using your distribution native package manager.\
\n\nOn Arch Linux, you can install it with \"sudo pacman -Sy libnotify\".\
\nOn Ubuntu, use \"sudo apt install libnotify-bin\"."
return 1 2>/dev/null
fi
# DEFINE COMMON VARIABLES
local turbostate=$(cat /sys/devices/system/cpu/intel_pstate/no_turbo);
local message_disabled="echo -e \"\nCPU Turbo is disabled!\"";
local message_enabled="echo -e \"\nCPU Turbo is enabled!\"";
local notification_disabled="notify-send -t 1000 -e -i computer-chip-symbolic\
-a 'CPU Turbo Checker 5000' 'CPU Turbo is disabled!'"
local notification_enabled="notify-send -t 1000 -e -i computer-chip-symbolic\
-a 'CPU Turbo Checker 5000' 'CPU Turbo is enabled!'"
# CHECK CPU TURBO STATUS
local status() {
if [[ $turbostate == "1" ]]; then
tput bold;
eval $message_disabled;
eval $notification_disabled;
tput sgr0;
else
tput bold;
eval $message_enabled;
eval $notification_enabled;
tput sgr0;
fi
}
# ENABLE CPU TURBO
local enable() {
if [[ $turbostate == "1" ]]; then
echo "0" | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo &>2 /dev/null;
tput bold;
eval $message_enabled;
eval $notification_enabled;
tput sgr0;
else
tput bold;
echo -e "Turbo already enabled!";
tput sgr0;
fi
}
# DISABLE CPU TURBO
local disable() {
if [[ $turbostate == "1" ]]; then
tput bold;
echo -e "Turbo already disabled!"
tput sgr0;
else
tput bold;
echo "1" | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo &>2 /dev/null;
eval $message_disabled;
eval $notification_disabled;
tput sgr0;
fi
}
# FUNCTION'S CLI OPTIONS
case "$1" in
-s)
status;;
-e)
enable;;
-d)
disable;;
-h | *)
status; echo -e "\
\nUsage:\
\n======\
\n\t-h\thelp\
\n\t-s\tstatus\
\n\t-e\tenable\
\n\t-d\tdisable";;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment