Files
dotfiles/.config/rofi/powermenu.sh
Julian Prein b96d32996b *: Wrap lines at 80 columns where appropriate
Wrap lines at 80 columns where appropriate and I had the energy to think
about how/where to wrap.

There are still lines longer than that, which I plan to wrap in the
future. But that is enough for now.
2022-06-23 23:59:00 +02:00

61 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Inspired by:
# https://github.com/cramermarius/rofi-menus/blob/master/scripts/powermenu.sh
# entries with associated commands
declare -A entries
entries=(
[lock]="xset s activate"
[logout]="i3-msg exit"
[reboot]="loginctl reboot"
[shutdown]="loginctl poweroff"
[suspend]="loginctl suspend"
[suspend (scheduled)]="scheduled_suspend"
)
declare -a rofi_args
rofi_args=(
-no-config
-theme /usr/share/rofi/themes/android_notification.rasi
-theme-str "#listview { lines: ${#entries[@]}; fixed-height: false; }"
-theme-str "#window { width: 12%; }"
-location 3
-yoffset 32
-dmenu
-no-case-sensitive
-p # -p at end for dynamic prompt
)
scheduled_suspend() {
declare -i min=0
min=$(rofi "${rofi_args[@]}" "minutes")
# make sure the input was a valid number
# side effect: 0 minutes is not possible
[[ "$min" -ne 0 ]] || exit 1
notify-send "suspend in" "$min minutes"
sleep $((min*60)) && ${entries[suspend]}
}
# Choose option over rofi
# Note: bash does not keep the order of the keys thus they get sorted
chosen="$(
printf '%s\n' "${!entries[@]}" \
| sort \
| rofi "${rofi_args[@]}" "power"
)"
# exit if nothing was selected
[[ -n "$chosen" ]] || exit 1
# handle scheduled suspend different
[[ "$chosen" != "suspend (scheduled)" ]] || { ${entries[$chosen]}; exit $?; }
# Confirm choice
yesNo="$(rofi "${rofi_args[@]}" "Confirm to ${chosen}" <<<$'no\nyes')"
# Exit if "No"
[[ "$yesNo" == "yes" ]] || exit 1
# Execute
${entries[$chosen]}