#!/usr/bin/env bash # ABOUTME: Rofi-basiertes Power-Menü für Moonarch (Niri). # ABOUTME: Bietet Shutdown, Reboot, Lock, Suspend und Logout. # CMDs uptime="`uptime -p | sed -e 's/up //g'`" host="$USER@"`hostname` # Options shutdown='󰤆' reboot='' lock='' suspend='' logout='󰗽' yes='' no='󰆢' # Rofi CMD rofi_cmd() { rofi -dmenu \ -p "$host uptime: $uptime" \ -mesg "$host uptime: $uptime" \ -theme /etc/xdg/rofi/powermenu/powermenu.rasi } # Confirmation CMD confirm_cmd() { rofi -dmenu \ -p 'Confirmation' \ -normal-window \ -mesg 'Confirm '${chosen} \ -theme /etc/xdg/rofi/powermenu/confirm.rasi } # Ask for confirmation confirm_exit() { echo -e "$yes\n$no" | confirm_cmd ${chosen} } # Pass variables to rofi dmenu run_rofi() { echo -e "$lock\n$suspend\n$logout\n$reboot\n$shutdown" | rofi_cmd } # Execute Command run_cmd() { selected="$(confirm_exit)" if [[ "$selected" == "$yes" ]]; then if [[ $1 == '--shutdown' ]]; then systemctl poweroff elif [[ $1 == '--reboot' ]]; then systemctl reboot elif [[ $1 == '--suspend' ]]; then mpc -q pause amixer set Master mute systemctl suspend elif [[ $1 == '--logout' ]]; then niri msg action quit fi else exit 0 fi } # Actions chosen="$(run_rofi)" case ${chosen} in $shutdown) run_cmd --shutdown ;; $reboot) run_cmd --reboot ;; $lock) killall rofi wlogout -P 1 -s -r 10 -c 10 ;; $suspend) run_cmd --suspend ;; $logout) run_cmd --logout ;; esac