Does anyone knows how to clear the clipboard content in Linux from within the CLI? Using a script or whatever.
I know KeePassXC does it, but I'm looking at the code and all it does is, if the screen manager is X11 it uses the Qt API, and if it's Wayland it calls wl-copy. As I'm in X11 I don't know what the fuck I should use.
I tried calling xclipboard but it says it's in use, probably by my DE or something.
@enigmatico maybe just xclip
? you should be able to fill the clipboard with emptyness, you need to specify the target correctly as x has like 3 clipboards
@lunareclipse@snug.moe I could install xclip but I'm looking if there is a more portable way since xclip doesn't seem to be available. But there doesn't seem to be anything portable.
@enigmatico @lunareclipse AFAIK it depends entirely on your desktop.
@fell@ma.fellr.net @lunareclipse@snug.moe Apparently it depends on your window manager. X11 and Wayland both have their own way of handling it, but both of them retain your clipboard in memory and obviously don't give you any simple and direct way to access it, so you have to rely on other tools to do that to you.
But my assumption is that this could be dangerous? Because maybe other tools would have easy access to your clipboard content and could potentially steal passwords and stuff? So not every distribution has xclip or the likes of installed by default? I'm guessing here.
However, the Qt framework, as well as the GTK+ library, can do that for you so I don't see the point at all? idk.
I was expecting to be able to handle the clipboard with something like a device in /dev or something, but nope.
@lunareclipse@snug.moe @fell@ma.fellr.net idk, I was just investigating it to see how it works.
On Windows everything is more "simple". Since it's all one single piece, everything is handled by the same API. But Linux is more complex because... Linux is just the kernel and everything else is just spare pieces forming the OS itself. So you have to always check which pieces can handle it and how each one handles it.
I guess the easiest way then is to just use the Qt or GTK+ libraries. Whatever is installed. Because xclip doesn't seem to be installed on every system. But then you need to ensure one of them are installed and... yeah... it's complicated.
@enigmatico @lunareclipse I have heard that on Linux the clipboard contents are never held in memory. When you press CTRL+C, the clipboard is just marked as belonging to that application. The data transfer only happens when you press CTRL+V. You can verify this by pressing CTRL+C and then closing the application. The clipboard will be gone. At least on my system it does that.