-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pryrc
55 lines (46 loc) · 1.55 KB
/
.pryrc
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
Pry.config.editor = "vim"
# prompt
Pry.config.prompt = [
proc {|target_self, nest_level, pry|
nested = (nest_level.zero?) ? '' : ":#{nest_level}"
"[#{pry.input_array.size}] #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}(#{Pry.view_clip(target_self)})#{nested}> "
},
proc {|target_self, nest_level, pry|
nested = (nest_level.zero?) ? '' : ":#{nest_level}"
"[#{pry.input_array.size}] #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}(#{Pry.view_clip(target_self)})#{nested}* "
}
]
# awesome_print
begin
require 'awesome_print'
Pry.config.print = proc { |output, value| output.puts value.ai }
rescue LoadError => err
puts "no awesome_print :("
end
# pry-clipboard
def pbcopy(str)
IO.popen('pbcopy', 'r+') {|io| io.puts str }
output.puts "-- Copy to clipboard --\n#{str}"
end
Pry.config.commands.command "hiscopy", "History copy to clipboard" do |n|
pbcopy _pry_.input_array[n ? n.to_i : -1]
end
Pry.config.commands.command "copy", "Copy to clipboard" do |str|
unless str
str = "#{_pry_.input_array[-1]}#=> #{_pry_.last_result}\n"
end
pbcopy str
end
Pry.config.commands.command "lastcopy", "Last result copy to clipboard" do
pbcopy _pry_.last_result.chomp
end
# Default Command Set, add custom methods here:
default_command_set = Pry::CommandSet.new do
command 'copy', 'Copy to clipboard' do |str|
str = "#{_pry_.input_array[-1]}#=> #{_pry_.last_result}\n" unless str
IO.popen('pbcopy', 'w') { |io| io.write str }
output.puts "-- Copy to clipboard --\n#{str}"
end
end
Pry.config.commands.import(default_command_set)