github-gist icon indicating copy to clipboard operation
github-gist copied to clipboard

-e / --empty option added

Open NH002 opened this issue 11 months ago • 0 comments

This new -e / --empty option allows -k / --keep and -x / --exchange options to operate on empty selections i.e. selections that are empty will not be ignored anymore.

So far, when it came to -k and -x options, if both PRIMARY or SECONDARY selections were empty (meaning NULL or ""), the program would simply "clear" them i.e. not ask for events associated with them anymore. This default behavior is not changed with this new addition; however, if now -e option is passed as well, selections that are NULL will be assigned a newly allocated "", and the program will proceed in the same way as if no selection were an empty string from the very beginning (since X server itself does not make a difference between "" and any other non-NULL selection).

This is something that may be useful if we want to preserve or exchange PRIMARY and SECONDARY selections on our system continuously, which we may achieve with this command: sh -c 'while xsel -kn; do :; done' (we let xsel -kn be our condition because it exits with failure immediately when the X session stops i.e. when the user logs out). The problem with that command is, since xsel -kn will exit immediately with success if both selections are empty, the command will create an insanely resource-consuming loop at startup; this issue may be mitigated in several ways, but the best one of which is this newly added -e option, which prevents such behavior: while xsel -ken; do :; done. A similar case is easy to imagine in case of -x option.

NH002 avatar Mar 12 '25 20:03 NH002