Skip to content

A Plan 9-inspired way to share your OS X clipboard to multiple hosts.

License

Notifications You must be signed in to change notification settings

eraserhd/osxsnarf

Repository files navigation

osxsnarf

A Plan 9-inspired way to share your OS X clipboard to multiple hosts.

This was taken from mirtchovski.com.

Installation

Assuming plan9port is installed, and 9 is in the path, you can build with the following commands:

$ make
$ sudo make prefix=/usr/local install

Running and Usage

You can have it listen on a Unix socket and post as a service where plan9port might expect to find it.

$ 9 ./osxsnarf 'unix!'"$(9 namespace)/snarf"
$ 9 9p ls snarf
snarf
$ printf 'hello, world!\n' |9 9p write snarf/snarf
$ pbpaste
hello, world!
$ 9 9p read snarf/snarf
hello, world!
$ printf 'goodbye, world!\n' |pbcopy
$ 9 9p read snarf/snarf
goodbye, world!

The weird quoting is to avoid Mac OS’s default bash from interpreting the !.

Forwarding the Snarf Service

You can share the service with other machines using 9 import or autossh. An example how to do this with autossh:

autossh -M 0 -f \
    -o 'StreamLocalBindUnlink yes' \
    -o 'ServerAliveInterval 30' \
    -o 'ServerAliveCountMax 3' \
    -o 'ExitOnForwardFailure yes' \
    -R"/path/to/remote/namespace/snarf:$(9 namespace)/snarf" \
    -T -N crunch.eraserhead.net

While this is running, both systems will have access to the OSX pasteboard.

StreamLocalBindUnlink instructs ssh to remove the forwarded unix socket on disconnect. Without this, if the connection is broken it will fail to re-establish, since ssh will not recreate the socket.

Configuring Kakoune

The following mappings are useful in Kakoune to interact with the system pasteboard via the "snarf" service:

# System clipboard handling
# ─────────────────────────
map global user -docstring 'paste (after) from clipboard' p '!9 9p read snarf/snarf<ret>'
map global user -docstring 'paste (before) from clipboard' P '<a-!>9 9p read snarf/snarf<ret>'
map global user -docstring 'yank to clipboard' y '<a-|>9 9p write  snarf/snarf<ret>:echo -markup %{{Information}copied selection to system clipboard}<ret>'
map global user -docstring 'replace from clipboard' R '|9 9p read snarf/snarf<ret>'

Bugs

  • There’s a fixed buffer size for text, about 192Kb. This should be dynamically allocated.

About

A Plan 9-inspired way to share your OS X clipboard to multiple hosts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published