From a0dde7e58d8e9cb19899dba1530077886d533b1e Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 29 Apr 2020 23:35:29 +0200 Subject: bin/swq: "has ws" and better support floatings cons --- bin/swq | 13 +++++++++---- 1 file 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 \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 \n\n' -- cgit 1.4.1