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

Stdout notifier #31

Closed
lentinj opened this issue May 6, 2022 · 2 comments · Fixed by #32
Closed

Stdout notifier #31

lentinj opened this issue May 6, 2022 · 2 comments · Fixed by #32

Comments

@lentinj
Copy link
Contributor

lentinj commented May 6, 2022

Thanks for this! I'm using it to display alerts via i3-nagbar with the following shell script, which is working nicely:

ALERT_PID=""

close_alert() {
    [ -n "${ALERT_PID}" ] && kill "${ALERT_PID}"
    ALERT_PID=""
}
trap close_alert EXIT INT TERM

"${YTD_BIN}" -v 2>&1 | grep --line-buffered -oP '(?<=\[notifiers/stdout\] )[^"]*' | while read -r L; do
    close_alert
    if [ "${L}" = "GPG_1" ] || [ "${L}" = "U2F_1" ]; then
        i3-nagbar -m "${L}: Press the Yubikey button" 2>/dev/null &
        ALERT_PID="$!"
    fi
done

This is too ugly for the wiki as-is though---parsing the debug output to extract messages is asking for trouble.

Admittedly I could use the systemd units and read from the unix socket like waybar-yubikey, but feels like needless complexity when my script could start it up for me. Would you be interested in a stdout notifier, activated with yubikey-touch-notifier --stdout that could go straight into a while loop like the above? Or is there reasoning behind the unix socket that I've missed?

Another minor point, "notifiers/stdout" is a misleading name for the messages, since nothing comes out of stdout. Would you accept a pull request to change it to "notifiers/stderr" to match the notifier name? "notifiers/debug" is probably more accurate, mind.

@maximbaz
Copy link
Owner

maximbaz commented May 6, 2022

Hello 👋

First of all, nice!

Yes to both 🙂 And if you can add your script to the wiki after we are done, it's also highly appreciated 🙂

Let's rename the current one to notifiers/debug, and let's have an explicit --stdout that maps to a new notifiers/stdout that prints events on stdout, so it would look like below, right?

$ yubikey-touch-detector --stdout
GPG_1
GPG_0
U2F_1
U2F_0
...

lentinj added a commit to lentinj/yubikey-touch-detector that referenced this issue May 15, 2022
Strictly speaking it doesn't output to stderr (or stdout), it writes
log messages that may end up on stderr. Rename to something more
obvious.
lentinj added a commit to lentinj/yubikey-touch-detector that referenced this issue May 15, 2022
Make it easier to use in scripts by having a stdout notifier that can
be ingested via. a pipe.
lentinj added a commit to lentinj/yubikey-touch-detector that referenced this issue May 22, 2022
If using -libnotify or -stdout, the socket will be redundant. Allow it
to be disabled.
@lentinj
Copy link
Contributor Author

lentinj commented May 24, 2022

Ace! Thanks for your help!

I'll combine what I've got with your bash script, which is better at managing multiple notifications than what I'm doing ATM, and add it to the wiki.

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

Successfully merging a pull request may close this issue.

2 participants