Clipboard History in Sway Window Manager

· 208 words · 1 minute read

Recently I switched to the Sway window manager on my favorite laptop and realized that ClipIt does not work there. I was reminded of an old Ruby script I wrote way back in 2012 to serve this purpose.

Time to dust that thing off and make it work with Wayland! I installed the excellent wl-clipboard by Sergey Bugaev and started hacking.

Here is my script:

Here’s how to use it:

  1. Save the script above to a file at /usr/local/bin/clipd and make it executable.

  2. Install dmenu if you don’t already have it.

  3. Install wl-clipboard from source. At the time of this writing, the package in the Ubuntu repository is fairly old and causes some screen glitching. The latest version on GitHub fixed that for me.

  4. Add the following config to your Sway config at ~/.config/sway/config:

    bindsym $mod+v exec clipd menu
    exec --no-startup-id clipd
    
  5. Restart Sway.

Now, when you copy text, clipd will see the new text (within 5 seconds) and add it to your ~/.clipboard-history file. It keeps the last 100 entries there.

When you press Mod + v, a menu will show the entries and allow you to make a selection. The item you select will be put back on the clipboard so you can paste it.

Enjoy!