summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-12-03 12:58:45 +0100
committerRobert Günzler <r@gnzler.io>2020-12-07 19:28:05 +0100
commit35936e5dda240ad3961fd17f65c75f8e2c2c9a4c (patch)
tree5a6081be4d90a158bf6345fa874a8824b7ce3ad0 /bin
parent2c1ccb5c21eb362c5b6ec013cf964dcfe9685e84 (diff)
Add bin/swkill; swq-based kill
Diffstat (limited to 'bin')
-rwxr-xr-xbin/swkill36
-rwxr-xr-xbin/swq4
2 files changed, 40 insertions, 0 deletions
diff --git a/bin/swkill b/bin/swkill
new file mode 100755
index 0000000..9a4a9ab
--- /dev/null
+++ b/bin/swkill
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# DESCRIPTION:
+#  kill the processes behind the containers returned by the `swq` query
+#
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+# check requirements
+for tool in jq swq; do
+				if ! command -v "$tool" >/dev/null; then
+								printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2
+								exit 1
+				fi
+done
+
+if [ "$1" = "-y" ]; then
+	shift
+	noninteractive=1
+fi
+
+sel="$*"
+if [ -z "$sel" ]; then
+	sel="current workspace"
+fi
+
+swq "$sel" | jq '.. | select(.pid?) | .name'
+
+if [ -z "$noninteractive" ]; then
+	{ sleep 10 && kill $$; } &
+	printf "kill? (you have 10s) "
+	read -r
+fi
+
+swq "$sel" | jq '.. | select(.pid?) | .pid' | xargs kill
diff --git a/bin/swq b/bin/swq
index 85f11a7..11128ee 100755
--- a/bin/swq
+++ b/bin/swq
@@ -1,4 +1,8 @@
 #!/usr/bin/env bash
+#
+# DESCRIPTION:
+#  convenience queries into the sway container tree
+#
 
 swtree()
 {