-
Notifications
You must be signed in to change notification settings - Fork 0
/
pryrc
114 lines (94 loc) · 2.9 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
require 'readline'
require 'pry-doc'
include Readline
# === EDITOR ===
Pry.editor = 'vim'
# === CUSTOM PROMPT ===
# This prompt shows the ruby version (useful for RVM)
default_prompt = Pry::Prompt[:default]
Pry.config.prompt = Pry::Prompt.new(
'custom',
'my custom prompt',
[
proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " },
proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }
]
)
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
begin
require 'awesome_print'
Pry.config.print = proc { |output, value| output.puts value.ai }
rescue LoadError
puts 'please install awesome_print'
end
begin
require 'hirb'
rescue LoadError
puts 'please install hirb'
end
if defined? Hirb
# Dirty hack to support in-session Hirb.disable/enable
Hirb::View.instance_eval do
def enable_output_method
@output_method = true
Pry.config.print = proc do |output, value|
Hirb::View.view_or_page_output(value) || output.puts(value.ai)
end
end
def disable_output_method
Pry.config.print = proc { |output, value| output.puts(value.ai) }
@output_method = nil
end
end
end
# === CUSTOM COMMANDS ===
# from: https://gist.github.com/1297510
default_command_set = Pry::CommandSet.new do
block_command "copy", "Copy argument to the clip-board" do |str|
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
end
block_command "clear" do
system 'clear'
if ENV['RAILS_ENV']
output.puts "Rails Environment: " + ENV['RAILS_ENV']
end
end
block_command 'disable_awesomeprint' do
Pry.print = Pry::DEFAULT_PRINT
end
block_command 'enable_autoload_debug' do
d = ActiveSupport::Dependencies
d.logger = Logger.new(STDOUT)
d.log_activity = true
end
block_command 'disable_autoload_debug' do
d = ActiveSupport::Dependencies
d.log_activity = false
end
block_command 'enable_awesome_print' do
Pry.config.print = proc { |output, value| output.puts value.ai }
end
block_command "sql", "Send sql over AR." do |query|
if ENV['RAILS_ENV'] || defined?(Rails)
pp ActiveRecord::Base.connection.select_all(query)
else
pp "No rails env defined"
end
end
block_command "caller_method" do |depth|
depth = depth.to_i || 1
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
output.puts [file, line, method]
end
end
end
Pry.config.commands.import default_command_set
Pry.commands.alias_command 'c', 'continue' if Pry.commands.keys.include?('continue')
Pry.commands.alias_command 's', 'step' if Pry.commands.keys.include?('step')
Pry.commands.alias_command 'n', 'next' if Pry.commands.keys.include?('next')