#!/usr/bin/env bash # vim: ft=bash ## Author : Aditya Shakya (adi1090x) ## Github : @adi1090x # ## Rofi : Power Menu # ## Available Styles # ## style-1 style-2 style-3 style-4 style-5 # Current Theme # CMDs uptime="`uptime -p | sed -e 's/up //g'`" host=`hostname` # Options shutdown='' reboot='' lock='' suspend='󰤄' logout='󰍃' yes='' no='' # Rofi CMD rofi_cmd() { rofi -dmenu \ -p "$host" \ -mesg "Uptime: $uptime" \ -theme powermenu.rasi } # Confirmation CMD confirm_cmd() { rofi \ -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 250px;}' \ -theme-str 'mainbox {children: [ "message", "listview" ];}' \ -theme-str 'listview {columns: 2; lines: 1;}' \ -theme-str 'element-text {horizontal-align: 0.5; }' \ -theme-str 'element {padding: 0px; }'\ -theme-str 'textbox {horizontal-align: 0.5;}' \ -dmenu \ -p 'Confirmation' \ -mesg 'Are you Sure?' \ -theme powermenu.rasi } # Ask for confirmation confirm_exit() { echo -e "$yes\n$no" | confirm_cmd } # 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 {{- if eq .chezmoi.os "linux" }} shutdown now {{- else }} shutdown -p now {{ end }} elif [[ $1 == '--reboot' ]]; then shutdown -r now elif [[ $1 == '--suspend' ]]; then {{- if eq .chezmoi.os "linux" }} systemctl suspend {{- else }} acpiconf -s 3 {{ end }} elif [[ $1 == '--logout' ]]; then if [[ "$XDG_SESSION_DESKTOP" == 'openbox' ]]; then openbox --exit elif [[ "$XDG_SESSION_DESKTOP" == 'bspwm' ]]; then bspc quit elif [[ "$XDG_SESSION_DESKTOP" == 'sway' ]]; then sway exit elif [[ "$XDG_SESSION_DESKTOP" == 'i3' ]]; then i3-msg exit elif [[ "$XDG_SESSION_DESKTOP" == 'plasma' ]]; then qdbus org.kde.ksmserver /KSMServer logout 0 0 0 fi fi else exit 0 fi } # Actions chosen="$(run_rofi)" case ${chosen} in $shutdown) run_cmd --shutdown ;; $reboot) run_cmd --reboot ;; $lock) if command -v swaylock 2>&1 >/dev/null; then swaylock -f -c 000000 --clock elif command -v betterlockscreen 2>&1 >/dev/null; then betterlockscreen -l elif command -v i3lock 2>&1 >/dev/null; then i3lock fi ;; $suspend) run_cmd --suspend ;; $logout) run_cmd --logout ;; esac