forked from JuanitoFatas/dotpryrc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pbcopy.rb
35 lines (31 loc) · 857 Bytes
/
pbcopy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Create command 'pbcopy' :
# Copy the last returned value in the Mac OS clipboard
# options : -m : Multiline copy
# Usage :
# a => [1, 2, 3]
# pbcopy
# [1, 2, 3]
# pbcopy -m
# [
# 1,
# 2,
# 3,
# ]
if RUBY_PLATFORM =~ /darwin/i # OSX only.
# The pbcopy manual page for Mac OS X
# http://goo.gl/o3nGsr
def pbcopy(str, opts = {})
IO.popen('pbcopy', 'r+') { |io| io.print str }
end
Pry.commands.command "pbcopy", "Copy last returned object to clipboard, -m for multiline copy" do
multiline = arg_string == '-m'
pbcopy _pry_.last_result.ai(
:plain => true,
:indent => 2,
:index => false,
:multiline => multiline
)
output.puts "Copied #{multiline ? 'multilined' : ''}!"
end
Pry.commands.alias_command 'cp', 'pbcopy'
end