2024-09-22 18:29:25 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
## Author : Aditya Shakya (adi1090x)
|
|
|
|
## Github : @adi1090x
|
|
|
|
#
|
|
|
|
## Rofi : Power Menu
|
|
|
|
#
|
|
|
|
## Available Styles
|
|
|
|
#
|
|
|
|
## style-1 style-2 style-3 style-4 style-5
|
|
|
|
|
|
|
|
# Current Theme
|
|
|
|
dir="$HOME/.config/rofi/power/power_menu.rasi"
|
|
|
|
|
|
|
|
# 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 \
|
|
|
|
-mesg " Uptime: $uptime" \
|
|
|
|
-theme ${dir}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Confirmation CMD
|
|
|
|
confirm_cmd() {
|
|
|
|
rofi -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 240px;}' \
|
|
|
|
-theme-str 'listview {columns: 2; lines: 1;}' \
|
|
|
|
-theme-str 'element-text {horizontal-align: 0.48;}' \
|
|
|
|
-theme-str 'textbox {horizontal-align: 0.5;}' \
|
|
|
|
-dmenu \
|
|
|
|
-p 'Confirmation' \
|
|
|
|
-mesg 'Are you Sure?' \
|
|
|
|
-theme ${dir}
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
loginctl poweroff
|
|
|
|
elif [[ $1 == '--reboot' ]]; then
|
|
|
|
loginctl reboot
|
|
|
|
elif [[ $1 == '--suspend' ]]; then
|
2024-10-03 23:56:28 +03:00
|
|
|
loginctl suspend
|
2024-09-22 18:29:25 +03:00
|
|
|
elif [[ $1 == '--logout' ]]; then
|
2024-10-03 23:56:28 +03:00
|
|
|
bspc quit & pkill pipewire & pkill pipewire-pulse & pkill polybar
|
2024-09-22 18:29:25 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Actions
|
|
|
|
chosen="$(run_rofi)"
|
|
|
|
case ${chosen} in
|
|
|
|
$shutdown)
|
|
|
|
run_cmd --shutdown
|
|
|
|
;;
|
|
|
|
$reboot)
|
|
|
|
run_cmd --reboot
|
|
|
|
;;
|
|
|
|
$lock)
|
|
|
|
if [[ -x '/usr/bin/betterlockscreen' ]]; then
|
2024-10-02 23:41:44 +03:00
|
|
|
betterlockscreen -l blur
|
2024-09-22 18:29:25 +03:00
|
|
|
elif [[ -x '/usr/bin/i3lock' ]]; then
|
|
|
|
i3lock
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
$suspend)
|
|
|
|
run_cmd --suspend
|
2024-10-03 23:56:28 +03:00
|
|
|
betterlockscreen -l blur
|
2024-09-22 18:29:25 +03:00
|
|
|
;;
|
|
|
|
$logout)
|
2024-10-03 23:56:28 +03:00
|
|
|
run_cmd --logout
|
2024-09-22 18:29:25 +03:00
|
|
|
;;
|
|
|
|
esac
|