From 5f2dbebf65dc5a2e528072a8eb0bac524d86257d Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 29 Jan 2020 16:09:39 +0100 Subject: Replace termify with swx Make swq match app_ids using jq's test() which allows "fuzzy" matching --- bin/swq | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'bin/swq') diff --git a/bin/swq b/bin/swq index 0336f64..a742d08 100755 --- a/bin/swq +++ b/bin/swq @@ -7,7 +7,7 @@ swtree() has_appid() { - swtree | jq "[ .. | select(.app_id?==\"$1\") // select(.window_properties?.class==\"$1\") // select(.window_properties?.instance==\"$1\") ]" + swtree | jq "[ .. | (select(.app_id?) | select(.app_id | test(\"$1\"))) // (select(.window_properties?.class?) | select(.window_properties.class | test(\"$1\"))) ]" } has_pid() @@ -82,16 +82,23 @@ _has() *) printf 'usage: swq has COMMAND \n' printf '\nCOMMANDS:\n' - printf ' appid: returns the json of the window filtered by app_id/class\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 '\n' + exit 2 ;; esac } _latest() { - [ "$1" == "ws" ] && 1="workspace" - latest "$1" + case "$1" in + workspace|ws) latest workspace ;; + container|con) latest con ;; + output) latest output ;; + *) + printf 'usage: swq latest \n\n' + exit 2 ;; + esac } _list() { @@ -109,7 +116,8 @@ _current() workspace) swtree | jq '.. | select(.type?=="workspace") | . as $parent | .nodes[]? | if .focused then $parent else empty end' ;; output) $0 current workspace | jq -r '.output' ;; *) - printf 'usage: swq current \n\n' ;; + printf 'usage: swq current \n\n' + exit 2 ;; esac } @@ -136,4 +144,5 @@ case "$1" in printf ' focus-latest-con\n' printf ' moveto : move container with to \n' printf '\n' + exit 2 ;; esac -- cgit 1.4.1