Made scripts more readable by moving most logic to functions.

This commit is contained in:
cronyakatsuki 2022-11-04 14:54:08 +01:00
parent 86e3a3a79c
commit 5c738fdc77
11 changed files with 234 additions and 133 deletions

View file

@ -1,8 +1,9 @@
#!/bin/sh
# dmenu script for quickly setting ryzenadj profiles with my other script easily
. $HOME/.config/dmenu/config
load_config () {
. $HOME/.config/dmenu/config
}
get_category () {
category=$( sudo ryzenset list | $DMENU -p "Choose profile category:")
@ -10,26 +11,43 @@ get_category () {
[ -z "$category" ] && exit 0
}
get_category
get_current_profile () {
current_temp=$(sudo get-tctl-limit)
current_temp=$(sudo get-tctl-limit)
[ "$current_temp" = "60" ] && current_mode="normal mode"
[ "$current_temp" = "65" ] && current_mode="light gaming"
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
[ "$current_temp" = "75" ] && current_mode="heavy programs"
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
}
[ "$current_temp" = "60" ] && current_mode="normal mode"
[ "$current_temp" = "65" ] && current_mode="light gaming"
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
[ "$current_temp" = "75" ] && current_mode="heavy programs"
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
menu () {
while [ -z "$profile" ]
do
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
while [ -z "$profile" ]
do
[ -z "$profile" ] && get_category
done
}
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
launch_profile () {
if sudo ryzenset set "$profile"; then
quick-notify "Ryzenset" "Setting $profile"
else
quick-notify "Ryzenset" "Failed to set $game"
fi
}
[ -z "$profile" ] && get_category
done
main () {
load_config
if sudo ryzenset set "$profile"; then
quick-notify "Ryzenset" "Setting $profile"
else
quick-notify "Ryzenset" "Failed to set $game"
fi
get_category
get_current_profile
menu
launch_profile
}
main $@