Giter Site home page Giter Site logo

trivial-clipboard's Introduction

trivial-clipboard

trivial-clipboard let access system clipboard.

Installation

(ql:quickload :trivial-clipboard)

Dependencies

  • CFFI (only on Windows)

Usage

get text from clipboard.

(trivial-clipboard:text)

put text to clipboard.

(trivial-clipboard:text "put text!")

Author

SANO Masatoshi ([email protected])

Project

License

Licensed under the MIT License.

trivial-clipboard's People

Contributors

aadcg avatar aartaka avatar aethor avatar ambrevar avatar cxxxr avatar simendsjo avatar snmsts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

trivial-clipboard's Issues

Don't Rely on XClip

xclip is not necessarily installed on every Linux system that uses X. It would probably be a better idea to do whatever it does in Lisp natively using clx.

Resolve commands at runtime instead of compile time

We have

(defvar *clipboard-in-command*
  #+(or darwin macosx)
  "pbcopy"
  #+(and :unix (:not :darwin))
  (or (executable-find "wl-copy")
      (executable-find "xclip")
      (executable-find "xsel")
      ""))

so when packaging a Lisp binary the commands are derived at compile time, which means the target machine needs to have the command at the same path. It's not practical for packagers, see atlas-engineer/nyxt#984 (comment).

Instead, I suggest making one defvar for each executable (wl-copy, xclip, etc.) and then a function which derives the command to use at run time.

Something like this (untested):

(defvar *in-commands* (append
                       #+(or darwin macosx) (list "pbcopy")
                       #+(and :unix (:not :darwin))
                       (list "wl-copy" "xclip" "xsel")))

(defun clipboard-in ()
  (some #'executable-find *in-commands*))

(defvar clipboard-in-args ()
  (progn
    '()
    #+ (and :unix (:not :darwin))
    (or (and (string= (pathname-name (clipboard-in-command)) "wl-copy")
             '())
        (and (string= (pathname-name (clipboard-in-command)) "xclip")
             '("-in" "-selection" "clipboard"))
        (and (string= (pathname-name (clipboard-in-command)) "xsel")
             '("--input" "--clipboard")))))

(defun text (&optional data)
  "If DATA is STRING, it is set to the clipboard. An ERROR is
signalled if the copy failed.

If DATA is NIL, TEXT returns the STRING from the clipboard. If the
copy failed, it returns NIL instead."
  (etypecase data
    (string
     #+os-windows
     (set-text-on-win32 data)
     #+(not os-windows)
     (with-input-from-string (input data)
       (uiop:run-program (cons (clipboard-in) (clipboard-in-args))
                         :input input))
     data)
    (null
     ;; ...
     )))

It would be a good opportunity to structure the code so that args are semantically bound to the command. But this probably belongs to a second commit.

Thoughts?

Wrong copy/paste command chosen on some systems

Hi,

I found a case where the command finding mechanism is not general enough. I use Fedora, where you can have both Wayland and X, and you choose which one to use when logging in. This lead to a case where I can use X, but wl-copy still exists. Therefore, when evaluating (trivial-clipboard:text "some text") using X, I get an error because:

  • trivial-clipboard:find-copy-command finds wl-copy first
  • wl-copy fails afterwards (which makes sense since Wayland is not started)

So relying on whether or not the command exists does not seem to handle all case. Maybe selecting a command should be done based on if it returns an error code or not ? In this case, wl-copy should be tried and, because it returns an error code, xclip should be selected instead. Let me know your thoughts on the issue. Happy to submit a PR if you're interested.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.