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

Can't cut kbdd_layout output down to 2 characters? #61

Closed
glubsy opened this issue Oct 16, 2016 · 3 comments
Closed

Can't cut kbdd_layout output down to 2 characters? #61

glubsy opened this issue Oct 16, 2016 · 3 comments

Comments

@glubsy
Copy link

glubsy commented Oct 16, 2016

I've been trying to cut down the output of kbdd_layout down to only the first 2 characters of the active keyboard layout.
My modifications work in terminal, the output is indeed what I want, but somehow i3blocks doesn't update properly.

First modification on line 37:

echo $( ( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
         /ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N ) | cut -c 4-5 )

This works in i3blocks fine, I get "En" as expected for the initial state.

But then, my second modification on line 41:

# Parse dbus output
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" | sed -un '0~2p' | \
        sed -un 's:.*string "\(.*\)".*:\1:p' | sed -u '/:/d' | sed -r 's/(.{2}).*/\1/'

Even if I replace the last sed by a cut -c '1-2', i3blocks doesn't update the output properly. Only this modification on line 41 makes this blocks to not work right. That last operation is causing issues, no matter which one it is...
Am I missing something obvious?

@kb100
Copy link
Collaborator

kb100 commented Oct 17, 2016

Since your changes work on the command line but not when called from i3blocks, I believe you are missing the fact that commands like sed have tricky caching optimizations that stop it from flushing stdout until some huge amount of data is accumulated first. Try using stdbuf, see e.g. https://github.com/vivien/i3blocks-contrib/blob/master/bandwidth/bandwidth, to stop commands doing such buffering.

@glubsy
Copy link
Author

glubsy commented Oct 18, 2016

Thank you very much for the reply!
Indeed stdbuf did the trick. 👍

dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" | sed -un '0~2p' | sed -un 's:.*string "\(.*\)".*:\1:p' | sed -u '/:/d' | stdbuf -oL cut -c 1-2

@glubsy glubsy closed this as completed Oct 18, 2016
@kb100
Copy link
Collaborator

kb100 commented Oct 18, 2016

I will add an FAQ entry as this seems to be a common issue, you're not alone.

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