Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard operations: xclip or pbcopy/pbpaste style operations. #656

Merged
merged 1 commit into from May 5, 2019

Conversation

pfcoperez
Copy link
Contributor

@pfcoperez pfcoperez commented Jul 5, 2017

One of production booster when working with terminals is the ability to read and write from and to the system clipboard.

This will be extremely useful to run Scala programs on data brought from selected text. An example is selecting part of Ammonite README file on GitHub:

Selected text

And counting words in the selected text:

val words = clipboard.read.split("\n").flatMap(_.split(" ").map(_.toLowerCase))

val wordCount = (Map.empty[String, Int] /: words) { (count, word) =>
    count + (word -> (count.getOrElse(word, 0)+1)) 
}

Result

I am open to discuss & change implementation details. I have some doubts:

  • I didn't consider this should be under FileOps so I created ClipboardOps
  • If the idea is welcomed further functionality could be added.
  • The code could be more abstract and generic.
  • ...

@lihaoyi lihaoyi closed this May 2, 2019
@pfcoperez
Copy link
Contributor Author

@lihaoyi Are you opposed to this kind of functionality or is it being provided in other PR? If the answer is no to both of this questions, I am open to following a different approach.

@lihaoyi
Copy link
Member

lihaoyi commented May 3, 2019

Haha i just closed it because i assumed it was stale. I think it looks good to me, but how about putting it in the ReplApi rather than in ammonite.ops? Then that i'll be happy to merge it

@lihaoyi lihaoyi reopened this May 3, 2019
@pfcoperez pfcoperez force-pushed the feature/clipboard branch 2 times, most recently from 2d00420 to 04bf770 Compare May 4, 2019 19:59
@lihaoyi
Copy link
Member

lihaoyi commented May 5, 2019

lgtm

@lihaoyi lihaoyi merged commit 5e5461b into com-lihaoyi:master May 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants