What I'd Like to do
I'd like to cut the output of the program
xkb-switch -W, which infinitely waits for layout group change, and prints group names to stdout. I'm only really interested in the first two characters of the output, so id like to cut it with
What I'm trying to accomplish
What I'm really trying to accomplish here is showing my current keyboard layout in my i3 bar with i3blocks, but I don't want the length of the line changing, since xkb-switch outputs not only the layout language (the first two characters), but also the layout variant, which I'm not interested in seeing. At the moment, this is what my block looks like:
[keymap] label= command=bash -c 'xkb-switch;xkb-switch -W' interval=persist
What I've tried
xkb-switch -W > foo & while inotifywait -qe modify foo; do cut -c1-2 foo; done
I tried hacking together this oneliner, where the output of xkb-switch is redirected to a file, and by using inotifywait to wait for modifications to the file, cut is called to output the two characters I want to get.
This doesn't work however, because the file isn't clobbered by xkb-switch the way I'd initially intended (I understand why this wouldn't work), and also inotifywait outputs "foo MODIFY" when the file is modified, which I do not want. I guess the latter could be amended by redirection of some sort. But I suspect what I've tried is not the best approach.