637751fd0a89a5531ea8eecfed67bda6d191496d — Edward Loveall 2 months ago 5bd5abc
Add pbcopy

This will copy any string to my macOS clipboard:


It works by creating a new output stream that pipes directly into the
`pbcopy` command using `IO.popen`. `popen` stands for "pipe open" and is
similar to the standard C `popen(3)` function. Imagine it's just like
`$stdout` but you can attach a command to it really easily.

It invokes `popen` with a block and simply `puts` the string into it.
Using a block argument automatically closes the IO.

Big shoutout to the Avdi Grimm and his https://graceful.dev/ videos for
teaching me about open pipe (which looks like `open("|command")`
instead), and postmodern for teaching me that `popen` is the better
choice because it shows more intention than `open("|command")`:
1 files changed, 6 insertions(+), 0 deletions(-)

M configs/dot-irbrc
M configs/dot-irbrc => configs/dot-irbrc +6 -0
@@ 7,3 7,9 @@ class Object
    (methods - Object.instance_methods).sort

class String
  def pbcopy
    IO.popen("pbcopy", "w") { |copy| copy.puts(self) }