summaryrefslogtreecommitdiff
path: root/config/rofi/powermenu/type-4/powermenu.sh
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2024-05-19 14:54:41 +0700
committeraltaf-creator <dev@altafcreator.com>2024-05-19 14:54:41 +0700
commit3ec8d42fbf6eed78c24de2caca63d91a2604ff50 (patch)
tree985517bcce150969a050f7f408bea6670177bbb7 /config/rofi/powermenu/type-4/powermenu.sh
Diffstat (limited to 'config/rofi/powermenu/type-4/powermenu.sh')
-rwxr-xr-xconfig/rofi/powermenu/type-4/powermenu.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/config/rofi/powermenu/type-4/powermenu.sh b/config/rofi/powermenu/type-4/powermenu.sh
new file mode 100755
index 0000000..17f20c7
--- /dev/null
+++ b/config/rofi/powermenu/type-4/powermenu.sh
@@ -0,0 +1,105 @@
+#!/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/powermenu/type-4"
+theme='style-5'
+
+# 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 "Goodbye ${USER}" \
+ -mesg "Uptime: $uptime" \
+ -theme ${dir}/${theme}.rasi
+}
+
+# Confirmation CMD
+confirm_cmd() {
+ rofi -dmenu \
+ -p 'Confirmation' \
+ -mesg 'Are you Sure?' \
+ -theme ${dir}/shared/confirm.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
+ 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
+ if [[ "$DESKTOP_SESSION" == 'openbox' ]]; then
+ openbox --exit
+ elif [[ "$DESKTOP_SESSION" == 'bspwm' ]]; then
+ bspc quit
+ elif [[ "$DESKTOP_SESSION" == 'i3' ]]; then
+ i3-msg exit
+ elif [[ "$DESKTOP_SESSION" == '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 [[ -x '/usr/bin/betterlockscreen' ]]; then
+ betterlockscreen -l
+ elif [[ -x '/usr/bin/i3lock' ]]; then
+ i3lock
+ fi
+ ;;
+ $suspend)
+ run_cmd --suspend
+ ;;
+ $logout)
+ run_cmd --logout
+ ;;
+esac