forked from giomatfois62/rofi-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrofi-session.sh
executable file
·44 lines (34 loc) · 1.12 KB
/
rofi-session.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# optional: i3lock
ROFI_CMD="rofi -dmenu -i -matching fuzzy"
USE_LOCKER="false"
LOCKER="i3lock"
entries="Lock Screen\nLog Out\nReboot\nShutdown\nSuspend\nHibernate"
declare -A commands=(
["Lock Screen"]=lock_screen
["Log Out"]=logout_user
["Reboot"]=reboot_sys
["Shutdown"]=shutdown_sys
["Suspend"]=suspend_sys
["Hibernate"]=hibernate_sys
)
confirm_action() {
local choice=$(echo -e "Yes\nNo" |\
rofi -p "Are you sure?" -dmenu -a 0 -u 1 -selected-row 1)
if [ $choice == "Yes" ]; then
echo $choice
fi
}
lock_screen() { loginctl lock-session ${XDG_SESSION_ID-}; }
logout_user() { loginctl terminate-session ${XDG_SESSION_ID-}; }
reboot_sys() { [ "$(confirm_action)" = "Yes" ] && loginctl reboot; }
shutdown_sys() { [ "$(confirm_action)" = "Yes" ] && loginctl poweroff; }
suspend_sys() { $($USE_LOCKER) && "$LOCKER"; loginctl suspend; }
hibernate_sys() { $($USE_LOCKER) && "$LOCKER"; loginctl hibernate; }
while choice=`echo -en $entries | $ROFI_CMD -p Session`; do
if [ ${#choice} -gt 0 ]; then
${commands[$choice]};
exit 0
fi
done
exit 1