Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an exit code when no players are running #119

Closed
UtkarshVerma opened this issue Jan 22, 2019 · 2 comments
Closed

Throw an exit code when no players are running #119

UtkarshVerma opened this issue Jan 22, 2019 · 2 comments

Comments

@UtkarshVerma
Copy link

I was currently writing a script for displaying playerctl details in i3bar and wanted to develop a case where the script shouldn't execute, that is when no players are active. My first thought was to use the playerctl status command and match it with "No players found" and it worked, but I wasn't able to suppress the excess output associated with it, that is "No players found". I also checked if playerctl throws an exit code when executing playerctl status in absence of any music players, and it doesn't. It always exits with zero exit code.
Therefore it would be great if the functionality of returning an error code other than 0 were implemented since that would enable me to use the following:

#Exit script if no players running
playerctl status 2>/dev/null || exit 3;
@acrisci
Copy link
Member

acrisci commented Jan 22, 2019

Yeah seems reasonable.

In the meantime:

if [[ $(playerctl status 2>&1) = "No players found" ]]; then
    exit 3
fi

@UtkarshVerma
Copy link
Author

UtkarshVerma commented Jan 23, 2019

@acrisci Thanks, that's quite similar to what I'm using as a workaround currently. But better since it doesn't rely on grep.

[[ $(playerctl status 2>&1 | grep "No players found") = "" ]] || exit 3;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants