-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
.pryrc
116 lines (95 loc) · 3.08 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Pry.config.input = Reline
begin
require 'pry-doc'
rescue LoadError
nil
end
Pry.config.editor = 'nano'
Pry.config.skip_cruby_source = true
# @ = whereami by default
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'q', 'exit-program'
Pry.commands.alias_command 'bt', 'pry-backtrace'
# TODO: ideally `main` at the top of the stack is cut off
Pry.commands.alias_command 'ss', 'stack -a'
# Pry.commands.alias_command '?', 'show-source'
# tried using pry-clipboard; wasn't loading for me
# https://gist.github.com/hotchpotch/1978295
def pbcopy(str)
IO.popen('pbcopy', 'r+') {|io| io.puts str }
puts "-- Copy to clipboard --\n#{str}"
end
def pbpaste
IO.popen('pbpaste') { |clipboard| clipboard.read }
end
def reload!
# TODO: this will not be accurate for non-rails projects!
root_dir = File.expand_path('..', __dir__)
root_dir = Rails.root if defined?(Rails)
verbose = $VERBOSE
$VERBOSE = nil
# Directories within the project that should be reloaded.
reload_dirs = %w[lib]
# Loop through and reload every file in all relevant project directories.
reload_dirs.each do |dir|
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each do |f|
load(f)
rescue StandardError
puts "error reloading file #{f}"
end
end
$VERBOSE = verbose
true
end
def locals
binding.callers[1].local_variables - %i[
__
_
_ex_
pry_instance
_out_
_in_
_dir_
_file_
]
end
Pry::Commands.block_command 'o', 'Open current line in VS Code' do |n|
file, line = pry_instance.binding_stack.first.source_location
# TODO got to be a faster way than shelling out
`code --goto #{file}:#{line}`
end
Pry::Commands.block_command 'clast', 'History copy to clipboard' do |n|
pbcopy pry_instance.input_ring[n ? n.to_i : -1]
end
Pry::Commands.block_command 'copy', 'Copy to clipboard' do |str|
str ||= "#{pry_instance.input_ring[-1]}#=> #{pry_instance.last_result}\n"
pbcopy str
end
Pry::Commands.block_command 'lastcopy', 'Last result copy to clipboard' do
pbcopy pry_instance.last_result.chomp
end
Pry.config.ls.separator = "\n" # new lines between methods
Pry.config.ls.heading_color = :magenta
Pry.config.ls.public_method_color = :green
Pry.config.ls.protected_method_color = :yellow
Pry.config.ls.private_method_color = :bright_black
# TODO https://gist.github.com/devonzuegel/c6e69d1d9981fc740a46
# TODO http://blog.nrowegt.com/ruby-rails-pry-tricks-part-2-3-more-cool-tricks/
# TODO https://wiki.josephhyatt.com/dotfiles/.pryrc
# TODO https://rocket-science.ru/hacking/2018/10/27/pry-with-whistles
# TODO https://github.com/amazing-print/amazing_print
class Object
# Return a list of methods defined locally for a particular object. Useful
# for seeing what it does whilst losing all the guff that's implemented
# by its parents (eg Object).
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
end
# fixes `help` output in `less`
# https://github.com/pry/pry/pull/2207
def (Pry::Pager::SystemPager).default_pager
'less -r -F -X'
end