OSDN Git Service

shutdown ask for confirmation
authorpaperbenni <paperbenni@gmail.com>
Thu, 27 Feb 2020 18:23:09 +0000 (19:23 +0100)
committerpaperbenni <paperbenni@gmail.com>
Thu, 27 Feb 2020 18:23:09 +0000 (19:23 +0100)
programs/instantshutdown

index 44cd13e..d6dcc91 100755 (executable)
@@ -6,19 +6,38 @@
 
 answer=$(echo " " | instantmenu -p "do you want to shut down?")
 
+# if there are apps open, ask for confirmation
+zconfirm() {
+    if wmctrl -l | grep -q '..'; then
+        echo "windows found"
+        if zenity --question --text="there are apps running, sure you want to $1"; then
+            echo "yes"
+            return 0
+        else
+            echo "no"
+            exit
+        fi
+    else
+        echo "no windows found"
+    fi
+}
+
 case "$answer" in
 y)
+    zconfirm "shutdown"
     rm ~/.instantosrunning
     sleep 0.4
     shutdown now
     ;;
 r)
+    zconfirm "reboot"
     rm ~/.instantosrunning
     sleep 0.4
     reboot
     ;;
 
 s)
+    zconfirm "sign out"
     rm ~/.instantosrunning
     sleep 0.4
     kill -9 -1