Multiple redirection
vredesbyyrd opened this issue ยท 5 comments
Hi, thanks for sharing this great tool!
I am attempting to combine xnotify
+ tiramisu
+ rofi
to make a notification system. Rofi will be used as a simple gui to view stored notifications.
Right now I am doing this to pipe to XNOTIFY_FIFO
and ROFI_NOTIFY
.
ROFI_NOTIFY=$HOME/.cache/rofi_notify
rm $ROFI_NOTIFY
touch -a $ROFI_NOTIFY
export XNOTIFY_FIFO="$HOME/.cache/xnotify$DISPLAY.fifo"
rm -f $XNOTIFY_FIFO
mkfifo $XNOTIFY_FIFO
xnotify 0<>$XNOTIFY_FIFO &
tiramisu -o "$(printf '#icon\t#id\t#actions\t#hints\t#source\t#summary: #body')" | tee $XNOTIFY_FIFO $ROFI_NOTIFY &>/dev/null &
It works as expected. But what I would like to do is redirect all of tiramisu's output to ROFI_NOTIFY
and only part of the output to XNOTIFY_FIFO
, specifically #source #summary: #body
.
I have tried a handful of things, but whatever I try the parsed output does not make it into XNOTIFY_FIFO
. eg
tiramisu -o "$(printf '#icon\t#id\t#actions\t#hints\t#source\t#summary: #body')" | tee -a $ROFI_NOTIFY | awk -F"\t" '{printf $5 $6}' > $XNOTIFY_FIFO &
If you have any pointers, I would love to hear them. Thanks for your time!
That problem is probably caused by buffered output.
Try to replace that pipeline with this:
tiramisu -o "$(printf '#icon\t#id\t#actions\t#hints\t#source\t#summary: #body')" | tee -a $ROFI_NOTIFY | awk -F"\t" '{printf $5 $6; fflush()}' > $XNOTIFY_FIFO &
Okay, so i screwed with this for like two hours before opening this issue, and just now figured it out.
tiramisu -o "$(printf '#icon\t#id\t#actions\t#hints\t#source\t#summary: #body')" | tee -a $ROFI_NOTIFY | awk -F'\t' '{ printf "%s\t%s", $5,$6; system("")}' > $XNOTIFY_FIFO &
awk
required system("")
to disable buffering.
Ill close this now. Sorry for the non-issue.
Whoops, commented at the exact same time it looks like. Thanks for the quick response though. fflush
does the trick to.
Thanks for the help!
I'd stick with fflush()
rather than system("")
, I think that the system
command flushing the output is a undefined behavior and undocumented (at least on the awk implementation I use).
EDIT: fflush()
is an extension, and some implementations may not have it.
Ill stick with fflush()
for now than. Good to know that some systems may lack it though. I wonder how old those implementations maybe... ill read into it a bit. And thanks for that clarification in your edit.
My shell scripting is very rusty, so I appreciate the tips!