summaryrefslogtreecommitdiff
path: root/.local/bin/desktop/i3exit
diff options
context:
space:
mode:
authorVikas Kushwaha <dev@vikas.rocks>2024-11-21 13:30:52 +0530
committerVikas Kushwaha <dev@vikas.rocks>2024-11-21 13:30:52 +0530
commit5c916d69d457101326803eb076a746060e3618cf (patch)
treed6fce3256eede1c1bf78fb6a1be75b9cc4b84cee /.local/bin/desktop/i3exit
Moved from github
Diffstat (limited to '.local/bin/desktop/i3exit')
-rwxr-xr-x.local/bin/desktop/i3exit54
1 files changed, 54 insertions, 0 deletions
diff --git a/.local/bin/desktop/i3exit b/.local/bin/desktop/i3exit
new file mode 100755
index 0000000..0be387c
--- /dev/null
+++ b/.local/bin/desktop/i3exit
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# with openrc use loginctl
+[ "$(cat /proc/1/comm)" = "systemd" ] && logind=systemctl || logind=loginctl
+
+command="$1"
+system_control() {
+ if [ "$(loginctl show-session --property=NCurrentSessions --value)" -gt 2 ]; then
+ notify-send --replace-id=4252 \
+ "i3exit" "Multiple users are logged in\nCant't $command"
+ exit
+ fi
+ eval "$@"
+}
+
+lockWall="$HOME/.local/share/lockWall"
+lock_desktop() {
+ [ -f "$lockWall" ] &&
+ i3lock --tiling --image="$lockWall" ||
+ i3lock --color=001177
+ pkill ssh-agent
+}
+
+case "$command" in
+ lock)
+ lock_desktop
+ xset dpms force off
+ ;;
+ logout)
+ switch-session
+ i3-msg exit
+ ;;
+ switch_user)
+ dm-tool switch-to-greeter
+ ;;
+ suspend)
+ lock_desktop; $logind suspend
+ ;;
+ hibernate)
+ system_control lock_desktop && $logind hibernate
+ ;;
+ reboot)
+ system_control $logind reboot
+ ;;
+ shutdown)
+ system_control $logind poweroff
+ ;;
+ *)
+ echo "== ! i3exit: missing or invalid argument ! =="
+ echo "Try again with: lock | logout | switch_user | suspend | hibernate | reboot | shutdown"
+ exit 2
+esac
+
+exit 0