astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.04k stars 75 forks source link

Clear clipboar after some time #61

Closed NgoHuy closed 4 years ago

NgoHuy commented 5 years ago

Hi, I use xclip for copy/paste from command line, I also use lockwise and bitwarden, they offer clear clipboard after some time. Can you implement it for xclip such as: --clear-time 10s? I know some work around like waiting for 10s then copy blank, but it's nice if it's default behavior.

Best regards, Severus

hackerb9 commented 4 years ago

You are copying passwords using the X clipboard selection? It seems like Unix sockets would be a better interprocess communication channel, but oh well.

Here's a script you can run which will clear your selection ten seconds after any program has copied something into it:

while xclip -verbose -selection clipboard </dev/null 2>/dev/null; do 
  echo -n "Waiting... "
  sleep 10
  echo "Cleared selection"
done

Note that the current version of xclip on github is buggy and may not work. If you use an older version, for example one that comes with your system's package manager, this script should do what you want.

kennbr34 commented 4 years ago

You can use the '-loops' feature to only serve one request (i.e. only allow it to be pasted once). You can also just select something else if you're using the primary selection (middle-click).

hackerb9 commented 4 years ago

Ken is right. The -loops 1 option is perfect for this. If you have to use the clipboard for secret communication, which I still think is a bad idea, this is better than waiting 10 seconds. It clears the clipboard as soon as you've used it.

NgoHuy commented 4 years ago

thank you, -loops is perfect