Replace infinite loop with single execution (waybar handles polling via interval), fix unquoted variables, simplify jq invocation.
71 lines
1.6 KiB
Bash
Executable File
71 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ABOUTME: Rofi-based CPU governor switcher using auto-cpufreq.
|
|
# ABOUTME: Allows switching between performance, powersave, and reset modes.
|
|
|
|
declare -A LABELS
|
|
declare -A COMMANDS
|
|
|
|
###
|
|
# List of defined 'bangs'
|
|
|
|
COMMANDS[""]="pkexec auto-cpufreq --force=performance"
|
|
LABELS[""]="Performance"
|
|
|
|
COMMANDS[""]='pkexec auto-cpufreq --force=powersave'
|
|
LABELS[""]="Powersave"
|
|
|
|
COMMANDS[""]='pkexec auto-cpufreq --force=reset'
|
|
LABELS[""]="Reset"
|
|
|
|
|
|
################################################################################
|
|
# do not edit below
|
|
################################################################################
|
|
##
|
|
# Generate menu
|
|
##
|
|
function print_menu()
|
|
{
|
|
for key in ${!LABELS[@]}
|
|
do
|
|
# echo "$key ${LABELS}"
|
|
echo "$key ${LABELS[$key]}"
|
|
# my top version just shows the first field in labels row, not two words side by side
|
|
done
|
|
}
|
|
##
|
|
# Show rofi.
|
|
##
|
|
function start()
|
|
{
|
|
# print_menu | rofi -dmenu -p "?=>"
|
|
print_menu | sort | rofi -theme /etc/xdg/rofi/themes/cpugov.rasi -show "CPU Modes" -dmenu -mesg " CPU Modes" -i -p "rofi-bangs: "
|
|
}
|
|
|
|
|
|
# Run it
|
|
value="$(start)"
|
|
|
|
# Split input.
|
|
# grab upto first space.
|
|
choice=${value%%\ *}
|
|
|
|
##
|
|
# Cancelled? bail out
|
|
##
|
|
if test -z "${choice}"
|
|
then
|
|
exit
|
|
fi
|
|
|
|
# check if choice exists
|
|
if test "${COMMANDS[$choice]+isset}"
|
|
then
|
|
# Execute the choice
|
|
${COMMANDS[$choice]}
|
|
|
|
dunstify --replace 553 -i "/usr/share/icons/zafiro-dark/devices/48/cpu.svg" "CPU Mode" "Set to $choice ${LABELS[$choice]}"
|
|
else
|
|
echo "Unknown command: ${choice}" | rofi -dmenu -p "error"
|
|
fi
|