From 2bcbbe0c3844cdd12fceb21de223c1325fe6a55b Mon Sep 17 00:00:00 2001 From: MisterZig <107263655+MisterZig@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:21:44 +0100 Subject: [PATCH] Update power-profiles Make the rofi menu hide options not available for the system by comparing the power profile for each predefined entry to the output of powerproflilesctl list --- etc/skel/.config/i3/scripts/power-profiles | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/etc/skel/.config/i3/scripts/power-profiles b/etc/skel/.config/i3/scripts/power-profiles index feb63dc5..e8835480 100644 --- a/etc/skel/.config/i3/scripts/power-profiles +++ b/etc/skel/.config/i3/scripts/power-profiles @@ -115,18 +115,32 @@ if ! command_exists systemctl ; then exit 1 fi -# menu defined as an associative array -typeset -A menu +# default_menu_options defined as an associative array +typeset -A default_menu_options -# Menu with keys/commands +# The default options with keys/commands -menu=( +default_menu_options=( [ Performance]="powerprofilesctl set performance" [ Balanced]="powerprofilesctl set balanced" [ Power Saver]="powerprofilesctl set power-saver" [ Cancel]="" ) +# The menu that will be displayed +typeset -A menu +menu=() + +# Only add power profiles that are available to menu +for key in "${!default_menu_options[@]}"; do + grep_arg=${default_menu_options[${key}]##* } + if powerprofilesctl list | grep -q "$grep_arg"; then + menu[${key}]=${default_menu_options[${key}]} + fi +done +unset grep_arg +unset default_menu_options + menu_nrows=${#menu[@]} # Menu entries that may trigger a confirmation message