glip
A clipboard interface for Go, compatible with Windows, Mac OS X, and Linux.
Usage
Install glip
like you would any other Go package:
go get github.com/stevenxie/glip
Since a glip.Board
(a clipboard interface) includes io.Writer
, io.Reader
,
io.WriterTo
, and io.ReaderFrom
, it can be used just about anywhere:
import (
"fmt"
"github.com/stevenxie/glip"
)
func main() {
glip.WriteString("snip snip")
out, _ := glip.ReadString()
fmt.Println(out)
}
Advanced Usage:
glip
provides API-wrapping structs specific to each clipboard-accessing
program; each struct implements the Board
interface.
If you know which specific program you would like to use, you can create a new
instance of the associated wrapper struct (i.e. PShellBoard
, Clip
,
DarwinBoard
, Xclip
, or Xsel
), and set program-specific flags / options
using the wrapper struct.
Compatibility
Windows:
glip
uses the the PowerShell Get-Clipboard
and Set-Clipboard
cmdlets to
read and write to the Windows clipboard.
If PowerShell is not available, the clip
command is used to write to the
Windows clipboard.
macOS:
glip
uses pbcopy
and pbpaste
commands on macOS.
Linux:
glip
requires the installation of either xclip
or xsel
to function on
Linux (since there's no built-in clipboard interface). glip
will choose
whichever program is available, with a preference for xsel
if both are
avaiklable.
Known Issues
glip
sometimes seems to fail arbitrarily on x86 Windows, and I'm not sure why.
It seems like the PowerShell clipboard modules are not very reliable?
If anybody can accurately diagnose the situation on a Windows machine, I'd
be very grateful 🙂.
glipboard
For an example of an application that uses glip
, check out glipboard
(located at /cmd/glipboard/
).
glipboard
was developed to both showcase how glip
can be used in a real
application, as well as to be a universal clipboard interface that external
programs can call in order to write to a system clipboard, if the underlying
commands are available.