scripts: Add hibernation to powermenu
Powermenu now correctly sets pc to suspend on the suspend action, and adds a new option hibernate which takes over the hibernation action. Additionally, suspend action sets the pc to 'suspend-then-hibernate' mode which means on low battery laptops will automatically switch to hibernation. (For now, pending additional PR we can also hibernate after certain time, see https://github.com/systemd/systemd/pull/25374 and https://teddit.net/r/archlinux/comments/zczdnq/systemctl_suspendthenhibernate_not_working_anymore/ for longer explanation)
This commit is contained in:
parent
4c540496dd
commit
6bc582f67a
1 changed files with 9 additions and 1 deletions
|
@ -13,6 +13,7 @@
|
||||||
# POWERMENU_LOCKSCREEN_CMD=""
|
# POWERMENU_LOCKSCREEN_CMD=""
|
||||||
# POWERMENU_LOGOUT_CMD=""
|
# POWERMENU_LOGOUT_CMD=""
|
||||||
# POWERMENU_SUSPEND_CMD=""
|
# POWERMENU_SUSPEND_CMD=""
|
||||||
|
# POWERMENU_HIBERNATE_CMD=""
|
||||||
# Command chooser options
|
# Command chooser options
|
||||||
# POWERMENU_PICKER_CMD=""
|
# POWERMENU_PICKER_CMD=""
|
||||||
# POWERMENU_PICKER_OPTS=""
|
# POWERMENU_PICKER_OPTS=""
|
||||||
|
@ -26,6 +27,7 @@ elif [ "${POWERMENU_SHOW_ICONS:-1}" -eq 1 ]; then
|
||||||
reboot_btn=""
|
reboot_btn=""
|
||||||
lock_btn=""
|
lock_btn=""
|
||||||
suspend_btn="鈴"
|
suspend_btn="鈴"
|
||||||
|
hibernate_btn="鈴"
|
||||||
logout_btn=""
|
logout_btn=""
|
||||||
fi
|
fi
|
||||||
if [ "${POWERMENU_SHOW_TEXT:-1}" -eq 1 ]; then
|
if [ "${POWERMENU_SHOW_TEXT:-1}" -eq 1 ]; then
|
||||||
|
@ -33,6 +35,7 @@ if [ "${POWERMENU_SHOW_TEXT:-1}" -eq 1 ]; then
|
||||||
reboot_btn="${reboot_btn} Restart"
|
reboot_btn="${reboot_btn} Restart"
|
||||||
lock_btn="${lock_btn} Lock Screen"
|
lock_btn="${lock_btn} Lock Screen"
|
||||||
suspend_btn="${suspend_btn} Suspend"
|
suspend_btn="${suspend_btn} Suspend"
|
||||||
|
hibernate_btn="${hibernate_btn} Hibernate"
|
||||||
logout_btn="${logout_btn} Log Out"
|
logout_btn="${logout_btn} Log Out"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -46,7 +49,7 @@ fi
|
||||||
selector_program="${POWERMENU_PICKER_CMD:-bemenu}"
|
selector_program="${POWERMENU_PICKER_CMD:-bemenu}"
|
||||||
selector_opts="${POWERMENU_PICKER_OPTS:--i}"
|
selector_opts="${POWERMENU_PICKER_OPTS:--i}"
|
||||||
|
|
||||||
menu=$(printf "%s\n" "$lock_btn" "$suspend_btn" "$power_off_btn" "$reboot_btn" "$logout_btn")
|
menu=$(printf "%s\n" "$lock_btn" "$suspend_btn" "$power_off_btn" "$reboot_btn" "$hibernate_btn" "$logout_btn")
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
result=$(printf "%s" "$menu" | $selector_program $selector_opts --prompt "$prompt")
|
result=$(printf "%s" "$menu" | $selector_program $selector_opts --prompt "$prompt")
|
||||||
|
|
||||||
|
@ -78,6 +81,11 @@ case "$result" in
|
||||||
;;
|
;;
|
||||||
"Suspend" | "$suspend_btn")
|
"Suspend" | "$suspend_btn")
|
||||||
if [ -n "$POWERMENU_SUSPEND_CMD" ]; then eval "$POWERMENU_SUSPEND_CMD"; else
|
if [ -n "$POWERMENU_SUSPEND_CMD" ]; then eval "$POWERMENU_SUSPEND_CMD"; else
|
||||||
|
systemctl suspend-then-hibernate
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"Hibernate" | "$hibernate_btn")
|
||||||
|
if [ -n "$POWERMENU_HIBERNATE_CMD" ]; then eval "$POWERMENU_HIBERNATE_CMD"; else
|
||||||
systemctl hibernate
|
systemctl hibernate
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue