redguardtoo / cliphist

Paste from clipboard manager into Emacs
75 stars 5 forks source link

Greenclip Support #13

Closed arkhan closed 3 years ago

arkhan commented 6 years ago

Hello, it's possible to add support for greenclipt https://github.com/erebe/greenclip thanks

redguardtoo commented 6 years ago

yeah, that's doable, I need do some research on its code

arkhan commented 6 years ago

Greetings, I'm trying to integrate greenclip and cliphist, but I still do not know how to do it

(list (s-split "\t" (shell-command-to-string "clipster -c -o -n 5 | awk '{gsub(/^ +| +$/,\"\")} {print \"\" $0 \"\"}'")))

I think that line can be used to obtain the elements of the clipboard

redguardtoo commented 6 years ago

Pull request is welcomed.

I'm not sure how to use greepclip.

Looks you need run greeclip daemon as clipboard server first. paste something, then run greenclip print to list all items. I noticed line-feed is changed into "\n" (one slash, one "n" character).

Check below code:

(autoload 'cliphist-flycut-read-items "cliphist-flycut" nil)
(autoload 'cliphist-parcellite-read-items "cliphist-parcellite" nil)
(autoload 'cliphist-clipit-read-items "cliphist-clipit" nil)

For example, you could use cliphist-clipit-read-items as sample, (split-string (shell-command-to-string "greenclip history") "[\r\n]+") could be a good start.

folliehiyuki commented 3 years ago

Hi. I use greenclip but am really new to Emacs (my elisp-fu nearly doesn't exist), so the best I can do right now is to provide some information. As stated with examples in greenclip's readme, an ideal way to retrieve an item from clipboard is with the command:

greenclip print | sed '/^$/d' | ???????????? | xargs -r -d'\n' -I '{}' greenclip print '{}'

where ????????? is our entry-selection program of choice. It would be nice if we can somehow "pipe" that into ivy :) The last greenclip print just re-copy the selected text and put it on top list again.

folliehiyuki commented 3 years ago

I made this with my little knowledge. It kinda works on its own. The problem is that when item is big, and contain vague characters like $, some shells (like fish-shell) will not like it and error out.

(defun ivy-greenclip ()
  "Select an item from clipboard history and re-copy it"
  (interactive)
  (let* ((history (split-string (shell-command-to-string "greenclip print | sed '/^$/d'") "[\r\n]+")))
    (ivy-read "Copy item from entry: "
              history
              :action (lambda (item)
                        (shell-command (concat "greenclip print '" item "'"))))))

greenclip replaces \n and \r with \xA0 before saving the item to the history file, so if we can do some regex replacing with item, that last command will not be needed.

redguardtoo commented 3 years ago

You can send me a pull request if you want my code merged.

@FollieHiyuki , try call-process api. shell-command is used when I was still not good at Emacs Lisp.

I don't think you need sed. Emacs has its own API replace-regexp-in-string.

folliehiyuki commented 3 years ago

Thanks. I have some more questions:

redguardtoo commented 3 years ago

https://www.gnu.org/software/emacs/manual/html_node/elisp/Non_002dASCII-in-Strings.html#Non_002dASCII-in-Strings

https://github.com/redguardtoo/cliphist/blob/master/cliphist.el#L131

folliehiyuki commented 3 years ago

Thanks for the info. I will take a look. This might take a while, since I have to learn lisp along the way as well.

redguardtoo commented 3 years ago

1ef5045 support greenclip (Chen Bin)

folliehiyuki commented 3 years ago

Thanks for your work, meanwhile I'm still fighting brackets :) I tried it out and it works. 1 concern though: I tend to not have my clipboard clutter up, so I usually delete the clipboard history once in while. cliphist currently saves cache when reading items. Adding a variable so that the users can control the caching behavior would be nice.

redguardtoo commented 3 years ago

cliphist will synchronise cache with clipboard manager if it's not empty. So you don't need worry about clearing cache.

If you really need manually empty cache, eval (setq cliphist-items nil).

folliehiyuki commented 3 years ago

That was the last missing piece I needed. I think you can close the issue.