clipnotify icon indicating copy to clipboard operation
clipnotify copied to clipboard

Continuous monitor mode

Open nick87720z opened this issue 4 years ago • 0 comments

I tried to implement persistent monitor daemon mode in simplest possible way (I guess it is). Without arguments act as usually. But if argument presents - enter mentioned monitor loop. Argument string is printed back on each clipboard change. This has little similarity to "yes" program, but besides being selective at when to print, it also uses only one argument - no concatenation is done. Argument "" should make it just a newline.

Now, instead of variant with shell loop, as in readme, more effective solutions could be used, e.g.:

stdbuf -oL clipnotify | awk '{...}'
stdbuf -oL clipnotify | sed -e '{e command' -e ';}'
(echo "command"; exec stdbuf -oL clipnotify) | sed -n -e '1{h;d;}; {g;e' -e ';}'

And as for user-supplied argument, it would allow more complex pipelines, where clipnotify has to crosstalk in parallel with other monitoring or notification tools, all in single shell block. E.g.:

( inotifywait --monitor --format 'filech:...' ... &
  pid=$?
  clipnotify clipch
  kill $pid
) | awk '
  /^clipch$/ {
    ...
  }
  /^filech:.../ {
    ...
  }'

NOTE: I tried various ways for text output, but all of them have drawbacks. So for now it has compile options, which may be passed via CFLAGS:

  • USE_FD - use write() against fd 1 (which should be obtained from stdio stream), otherwise - regular fwriter. This effectively sets aside buffering issues, but could have problems due to being as simple as possible, and for now I did not try to handle even elementary issues, such as when write() call is interrupted by signal handler before can complete. Well, if there are default meaningful signal handlers.
  • USE_UNLOCKED_IO - use unlocked thread-unsafe variants for whatever is used from stdio.h, if available of course (fileno_unlocked with USE_FD, fwrite_unlocked otherwise). I did not notice any source of threads, so assuming this should cause no problems,
  • USE_ALLOCA - this is for argument string duplicate with newline replacing terminating null, for use with fwrite/write code variant (other variants - below). I know, this makes it to be placed in stack, and instead of being horrified just use with proper caution (no idea, if VLA better than this). Someone else would just use fixed-size array for buffer.

Also I have left commented out variants, using just printf and dprintf. I tried write just to avoid unneeded formating support. Could be just fputs(), but in fwrite I specify string length, which doesn't change through program run.


So - for now I would like to know, if some options are redundant or useless, where single choice would suffice all cases,

Update: as for me, I use hardcoded alloca+fwrite_unlocked combo (in user patch, usable with gentoo package).

Fixes #16

nick87720z avatar Jan 08 '22 22:01 nick87720z