X11 clipboard history and management using spmenu
Go to file
Chris Down 9c16837227 clipctl: Make pgrep regex less taxing
For some reason, .* is really taxing for pgrep, but if you remove it
it's way faster...

    % \time -v pgrep -nf '.*clipmenud$'
    325286
	    Command being timed: "pgrep -nf .*clipmenud$"
	    User time (seconds): 0.83
	    System time (seconds): 0.00
	    Percent of CPU this job got: 100%
	    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.83
	    Average shared text size (kbytes): 0
	    Average unshared data size (kbytes): 0
	    Average stack size (kbytes): 0
	    Average total size (kbytes): 0
	    Maximum resident set size (kbytes): 7632
	    Average resident set size (kbytes): 0
	    Major (requiring I/O) page faults: 0
	    Minor (reclaiming a frame) page faults: 1418
	    Voluntary context switches: 1
	    Involuntary context switches: 3
	    Swaps: 0
	    File system inputs: 0
	    File system outputs: 0
	    Socket messages sent: 0
	    Socket messages received: 0
	    Signals delivered: 0
	    Page size (bytes): 4096
	    Exit status: 0
    % \time -v pgrep -nf 'clipmenud$'
    325286
	    Command being timed: "pgrep -nf clipmenud$"
	    User time (seconds): 0.04
	    System time (seconds): 0.00
	    Percent of CPU this job got: 100%
	    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.04
	    Average shared text size (kbytes): 0
	    Average unshared data size (kbytes): 0
	    Average stack size (kbytes): 0
	    Average total size (kbytes): 0
	    Maximum resident set size (kbytes): 7320
	    Average resident set size (kbytes): 0
	    Major (requiring I/O) page faults: 0
	    Minor (reclaiming a frame) page faults: 1257
	    Voluntary context switches: 1
	    Involuntary context switches: 7
	    Swaps: 0
	    File system inputs: 0
	    File system outputs: 0
	    Socket messages sent: 0
	    Socket messages received: 0
	    Signals delivered: 0
	    Page size (bytes): 4096
	    Exit status: 0
2020-03-28 14:12:49 +00:00
init systemd: Use 500ms RestartSec 2019-02-13 16:34:32 +00:00
tests Use a single line cache file 2020-03-23 13:00:14 +00:00
.travis.yml clipmenud: Allow disable with USR1 and enable with USR2 2020-03-25 19:13:22 +00:00
clipctl clipctl: Make pgrep regex less taxing 2020-03-28 14:12:49 +00:00
clipdel Use a single line cache file 2020-03-23 13:00:14 +00:00
clipfsck Use a single line cache file 2020-03-23 13:00:14 +00:00
clipmenu clipmenu: print selection to stdout 2020-03-24 18:00:20 -07:00
clipmenud clipmenud: Store the last data on reenabling 2020-03-26 00:35:31 +00:00
LICENSE License as public domain 2015-10-26 11:10:54 +00:00
Makefile makefile: Install clipctl 2020-03-25 19:22:22 +00:00
README.md readme: Tersify and use British English 2020-03-25 19:13:22 +00:00

Tests

clipmenu is a simple clipboard manager using dmenu (or rofi with CM_LAUNCHER=rofi) and xsel.

Demo

Demo

Usage

Start clipmenud, then run clipmenu to select something to put on the clipboard. For systemd users, a user service called clipmenud is packaged as part of the project.

You may wish to bind a shortcut in your window manager to launch clipmenu.

All args passed to clipmenu are transparently dispatched to dmenu. That is, if you usually call dmenu with args to set colours and other properties, you can invoke clipmenu in exactly the same way to get the same effect, like so:

clipmenu -i -fn Terminus:size=8 -nb '#002b36' -nf '#839496' -sb '#073642' -sf '#93a1a1'

For a full list of environment variables that clipmenud can take, please see clipmenud --help.

Features

The behavior of clipmenud can be customized through environment variables. Despite being only <300 lines, clipmenu has many useful features, including:

  • Customising the maximum number of clips stored (default 1000)
  • Disabling clip collection temporarily with clipctl disable, reenabling with clipctl enable
  • Not storing clipboard changes from certain applications, like password managers
  • Taking direct ownership of the clipboard
  • ...and much more.

Check clipmenud --help to view all possible environment variables and what they do. If you manage clipmenud with systemd, you can override the defaults by using systemctl --user edit clipmenud to generate an override file.

Installation

Several distributions, including Arch and Nix, provide clipmenu as an official package called clipmenu.

Manual installation

If your distribution doesn't provide a package, you can manually install using make install (or better yet, create a package for your distribution!). You will need xsel and clipnotify installed, and also dmenu unless you plan to use a different launcher.

How does it work?

clipmenud is less than 300 lines, and clipmenu is less than 100, so hopefully it should be fairly self-explanatory. However, at the most basic level:

clipmenud

  1. clipmenud uses clipnotify to wait for new clipboard events.
  2. If clipmenud detects changes to the clipboard contents, it writes them out to the cache directory and an index using a hash as the filename.

clipmenu

  1. clipmenu reads the index to find all available clips.
  2. dmenu is executed to allow the user to select a clip.
  3. After selection, the clip is put onto the PRIMARY and CLIPBOARD X selections.