cliphist
cliphist copied to clipboard
Add wofi example that handles quotes correctly
The example for removing the id number of history items for wofi doesn't handle quotes correctly. I added a snippet that does (I hope).
It's very cursed. I am sorry.
A short explanation taken from my dotfiles I wrote for myself so I don't forget:
"The gist is: the %q in printf quotes the string in a shell-compatible way. Thanks to that, we can put in --pre-display-cmd with %s in wofi, and the string will be correctly interpreted there, even if it contains quotes or stuff itself.
The pre-display-cmd is there for removing the leading ID number (separated by tab) in the history item string so it isn't displayed, but not removed from the actual string passed back to cliphist. See https://github.com/sentriz/cliphist#faq
Using xargs, we give the quoted string to bash, which then interprets the quotes, and echo out the unquoted string, which we can then finally pass back to cliphist."
I've also added -n to the echo call so it doesn't emit a newline, and -z to the cut call for the same reason. Without it, wofi was showing each entry on two lines for me.
see also my dotfiles: https://git.eisfunke.com/config/nixos/-/commit/d726ba6a3a22d7d7ae445c6ac95b7670c73a451c
thanks! and very cursed indeed 😁 I wonder would it be a similar effort to just make a PR to wofi to just take the pre-display-cmd just read the line from stdin. then we never have to think about quoting and the command could just be something like awk { print $2 }
Just to pick the brains of either of you (if you have the time). I've set up image escaping with wofi (see this gist that correctly shows the thumbnails of copied images alongside the text). I've been unsuccessful at getting rid of the ID number on non-text entries though.
The exact difficulty is that if we strip the ID and tab char through a --pre-display-cmd, we might end up having a clipboard entry beginning with img: (the escape sequence that allows images to be rendered) that could cause some undesired/unpredictable behaviour. Would there be a better approach than to insert some character like > that doesn't pollute the clipboard too much?
Edit: wofi running the command on image-escaped sequences might not be desired behaviour in wofi. I think this might address the issue, so will investigate and perhaps open a PR with wofi itself.