~tsdh/public-inbox

6 3

[swayr] nop <criteria> && command

Details
Message ID
<CS7B2SYQ8C29.YTNUY03RWLOX@gb1>
DKIM signature
missing
Download raw message
`swaymsg <criteria> nop` returns a non-zero return value on failure,
allowing conditional decisions for use in scripting.

```
$ swaymsg '[app_id="foot"]' nop ; echo $?
0
$ swaymsg '[app_id="foot"]' nop ; echo $?
Error: No matching node.
2
$
```

I think it would be useful if the swayr nop command could do this as well.

I imagine it would make scripting easier by allowing simple use of
OR, NOT, and nesting of conditions that cannot be specified with `swaymsg`.
Details
Message ID
<87ildhbt47.fsf@gnu.org>
In-Reply-To
<CS7B2SYQ8C29.YTNUY03RWLOX@gb1> (view parent)
DKIM signature
missing
Download raw message
"Takahashi, Naoki" <tkna91@gmail.com> writes:

> `swaymsg <criteria> nop` returns a non-zero return value on failure,
> allowing conditional decisions for use in scripting.
>
> ```
> $ swaymsg '[app_id="foot"]' nop ; echo $?
> 0
> $ swaymsg '[app_id="foot"]' nop ; echo $?
> Error: No matching node.
> 2
> $
> ```

Interesting, I didn't know that!

> I think it would be useful if the swayr nop command could do this as
> well.

Yes, absolutely.  I'll make it so when I find some spare time. :-)

Bye,
Tassilo
Details
Message ID
<CS7EZ38TOAB1.1XKJGAF79V8JQ@gb1>
In-Reply-To
<87ildhbt47.fsf@gnu.org> (view parent)
DKIM signature
missing
Download raw message
Sorry, my example was a bit wrong. It is as follows.

```
$ swaymsg '[app_id="foot"]' nop ; echo $?
0
$ swaymsg '[app_id="foott"]' nop ; echo $?
Error: No matching node.
2
$
```
Details
Message ID
<87wn1vlp5v.fsf@gnu.org>
In-Reply-To
<87ildhbt47.fsf@gnu.org> (view parent)
DKIM signature
missing
Download raw message
Tassilo Horn <tsdh@gnu.org> writes:

>> I think it would be useful if the swayr nop command could do this as
>> well.
>
> Yes, absolutely.  I'll make it so when I find some spare time. :-)

It's done!  However, I didn't extend the nop command but the (until now
undocumented) get-windows-as-json command.  See the last command in
https://sr.ht/~tsdh/swayr/#miscellaneous-commands.

It's only in the main branch so far but I'll release 0.26.0 shortly.  It
would be great if you could do some testing.

Bye,
Tassilo
Details
Message ID
<CS8YJMPMCY08.13XYNPAVYU8M8@gb1>
In-Reply-To
<87wn1vlp5v.fsf@gnu.org> (view parent)
DKIM signature
missing
Download raw message
Thanks. As far as I'm briefly testing it now, it doesn't seem to have any glitches.

I think it would be easy to understand if you could do the same thing with 'swayr nop <CRITERIA>' as below, but what do you think?

```
$ swayr get-windows-as-json --error-if-no-match --matching '[app_name="foot"]' >/dev/null ; echo $?
0
$ swayr get-windows-as-json --error-if-no-match --matching '[app_name="foott"]' >/dev/null ; echo $?
Error: "No matching windows"
1
$ 
```
Details
Message ID
<87edo3dqjt.fsf@gnu.org>
In-Reply-To
<CS8YJMPMCY08.13XYNPAVYU8M8@gb1> (view parent)
DKIM signature
missing
Download raw message
"Takahashi, Naoki" <tkna91@gmail.com> writes:

> Thanks. As far as I'm briefly testing it now, it doesn't seem to have
> any glitches.

Thanks!

> I think it would be easy to understand if you could do the same thing
> with 'swayr nop <CRITERIA>' as below, but what do you think?

You mean, make "swayr nop <CRITERIA>" an alternative to "swayr
get-windows-as-json -m <CRITERIA> -e" just without the JSON output?  If
that's the question, the answer is a No because the nop command already
has a specific meaning in swayr: it ends the current next/prev sequence.
It it were used by shell scripts, this effect could lead to strange
effects.  It would basically be an auto-nop triggered at possibly random
times by scripts.

Oh, now that I've written the above it occurs to me that
get-windows-as-json will do the same!  So I'll add an exception that
this command, which is just a tool for scripting, doesn't end the
current next/prev sequence. :-)

Bye,
Tassilo
Details
Message ID
<CS9CDIPLR209.129108496YE26@gb1>
In-Reply-To
<87edo3dqjt.fsf@gnu.org> (view parent)
DKIM signature
missing
Download raw message
Understood. It seems that the original purpose was different,
so it cannot be replaced with another function.
Thank you for the implementation.
I'm pleased it has become more convenient.
Reply to thread Export thread (mbox)