summary refs log tree commit diff
path: root/bin/swq
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-04-29 23:35:29 +0200
committerRobert Günzler <r@gnzler.io>2020-04-29 23:35:29 +0200
commita0dde7e58d8e9cb19899dba1530077886d533b1e (patch)
tree57ae40bc035a8ff037bb1efb960f1e3bf0ca86e7 /bin/swq
parentad220601cb0d4e495662b9c3166a7ba9dc208917 (diff)
bin/swq: "has ws" and better support floatings cons
Diffstat (limited to 'bin/swq')
-rwxr-xr-xbin/swq13
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/swq b/bin/swq
index a742d08..ba6e382 100755
--- a/bin/swq
+++ b/bin/swq
@@ -49,6 +49,9 @@ has_exe()
     fi
     has_pid "$pid_of_win"
 }
+has_ws() {
+    swtree | jq "[ .. | select(.type?==\"workspace\" and .name?==\"$1\") ]"
+}
 
 latest()
 {
@@ -79,12 +82,14 @@ _has()
         appid) has_appid "$2" ;;
         pid) has_pid "$2";;
         exe) has_exe "$2";;
+        ws) has_ws "$2";;
         *)
             printf 'usage: swq has COMMAND <args>\n'
             printf '\nCOMMANDS:\n'
             printf ' appid: returns the json of the window filtered by app_id/class (fuzzy matching)\n'
-            printf ' pid:   returns the json of the window filtered by pid\n'
-            printf ' exe:   returns the json of the window filtered by process name\n'
+            printf ' pid:   returns json of the window filtered by pid\n'
+            printf ' exe:   returns json of the window filtered by process name\n'
+            printf ' ws:    returns json of the window filtered by workspace\n'
             printf '\n'
             exit 2 ;;
     esac
@@ -110,10 +115,10 @@ _current()
 {
     case "$1" in
         window) _current con ;;
-        con) swtree | jq '.. | select(.type?=="con" and .focused?==true)' ;;
+        con) swtree | jq '.. | select((.type? | test("con")?) and .focused?)' ;;
 
         ws) _current workspace ;;
-        workspace) swtree | jq '.. | select(.type?=="workspace") | . as $parent | .nodes[]? | if .focused then $parent else empty end' ;;
+        workspace) swtree | jq '.. | select(.type?=="workspace") | . as $parent | $parent.nodes[]?, $parent.floating_nodes[]? | if .focused? then $parent else empty end' ;;
         output) $0 current workspace | jq -r '.output' ;;
         *)
             printf 'usage: swq current <con|workspace|output>\n\n'