xtermcontrol icon indicating copy to clipboard operation
xtermcontrol copied to clipboard

Return a non-zero exit code when an operation cannot be performed

Open odisseus opened this issue 5 years ago • 4 comments

Example

$ xtermcontrol --get-bg
xtermcontrol: --get-bg is unsupported or disallowed by this terminal. See also, TROUBLESHOOTING section of xtermcontrol(1) manpage.
$ echo $?
0

If xtermcontrol returned something else than zero, it would be much easier to handle such situations in scripts.

odisseus avatar Feb 14 '20 23:02 odisseus

That is tricky because xtermcontrol accepts multiple arguments that may succeed or fail independently, e.g.

$ xtermcontrol --get-fg --get-title
rgb:0000/0000/0000
xtermcontrol: --get-title is unsupported or disallowed by this terminal. See also, TROUBLESHOOTING section of xtermcontrol(1) manpage.

As a workaround for your example, perhaps test stdout or make a small wrapper script?

#!/bin/bash

bg=$(xtermcontrol --get-bg 2>/dev/null)
if [[ -z $bg ]]; then
  exit 1
else
  echo $bg
fi

JessThrysoee avatar Feb 15 '20 12:02 JessThrysoee

Perhaps a non-zero exit code is warranted if none of the requests succeed? This would cover my case as well.

odisseus avatar Feb 15 '20 19:02 odisseus

How about exiting with the number of failed requests? That'd cover the successful case and allow to differentiate between complete and partial failures.

swsnr avatar Apr 16 '20 07:04 swsnr

I need this too, I think having to create a wrapper script to get a status is too much.

I like the idea of returning the number of failed operations best, but fail-if-all-fail is also okay with me.

There is also the possibility of having an option to turn on (or off) reporting a nonzero status if an operation fails.

reikred avatar Apr 12 '23 20:04 reikred