-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pryrc
55 lines (45 loc) · 1.56 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
Pry.config.editor = "nvim"
Pry.config.color = true
Pry.config.prompt_name = "[pry]"
Pry.config.prompt = proc do |obj, nest_level, _pry_|
current_branch = `git rev-parse --abbrev-ref HEAD 2>/dev/null`.chomp
current_branch = "#{current_branch[0..14]}.." if current_branch.length > 16
current_branch = "(#{current_branch})" if current_branch
num = "[#{_pry_.input_ring.size}]" if _pry_.respond_to?(:input_ring)
num = "[#{_pry_.input_array.size}]" if _pry_.respond_to?(:input_array)
"#{num} #{current_branch} (#{Pry.view_clip(obj)})> "
end
Pry.config.commands.import(Pry::CommandSet.new do
command 'reload!', 'Reload Pry' do
target.eval <<-EVAL
at_exit { puts "Reloading pry..."; exec "pry" }
exit
EVAL
end
alias_command 'r', 'reload!'
end)
if defined?(PryByebug)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
Pry.commands.alias_command 'w', 'whereami'
Pry.commands.alias_command 'vi', 'edit'
end
command_set = Pry::CommandSet.new do
command 'sql', 'sqlを実行する' do |sql|
if defined?(Rails)
if sql.match('\Aselect')
result = ActiveRecord::Base.connection.select_all(sql)
output.puts result.to_hash
else
result = ActiveRecord::Base.connection.execute(sql)
output.puts result.to_hash
end
end
end
command "copy", "Copy argument to the clip-board" do |str|
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
end
end
Pry.config.commands.import command_set