[enhancement] exit code parameter for cli
paw-lu opened this issue · 3 comments
Been thinking of a way to automatically trigger success
/error
sounds based on whether the previous command succeeded on the terminal.
One way to accomplish this would be an --exit-code
(-e
) argument to be used as such:
% ls; chime --exit-code=$?
$?
in bash and zsh stores the exit code of the previous command. An exit-code
argument would allow the user to input it into chime, triggering an error
on a non-zero exit code, success
otherwise.
To be honest I wish there was a more automated way to handle this, but this is the best I can come up with at the moment!
Yes I agree that chiming with respect to the exit code would be wonderful. Maybe there's some way to pipe |
or to redirect >
into the chime command?
Maybe there's some way to pipe | or to redirect > into the chime command?
Haven't come across anything straightforward. The only way I could think of to getting the exit code it into stdin would be:
% command; echo $? | chime
Another option is for Chime acts as a wrapper for a command, running the command using os.system
, or something like that. It would then have access to the exit code. This seems a bit complex to me, as chime would take on a bit of responsibility that the arbitrary command works as expected, and it might end up being a bit fragile. Open to ideas though!
This is a very old issue, but I'd like to add this for anyone stumbling upon it from their search engine:
In Linux, you can use logical operators to achieve largely the same functionality.
command && chime || chime error
This would produce the success sound if command
is successful, otherwise it would produce the error sound.