-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path.pryrc
90 lines (77 loc) · 2.27 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
Pry.config.editor = "vim"
# https://github.com/kyrylo/pry-theme
Pry.config.theme = "pry-modern"
# See https://gist.github.com/807492
# Use Array.toy to get an array to play with
class Array
def self.toy(n=10, &block)
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end
end
# Use Hash.toy to get an hash to play with
class Hash
def self.toy(n=10)
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
end
end
# interactive editor: use my favorite editor from within irb
begin
require '~/Code/Project/interactive_editor/lib/interactive_editor.rb'
rescue LoadError => err
warn "Couldn't load interactive_editor: #{err}"
end
# From: https://gist.github.com/rondale-sc/1297510
# Default Command Set, add custom methods here:
default_command_set = Pry::CommandSet.new do
# command "copy", "Copy argument to the clip-board" do |str|
# IO.popen('pbcopy', 'w') { |f| f << str.to_s }
# end
command "clear" do
system 'clear'
if defined?(Rails)
output.puts "Rails Environment: #{Rails.env}"
end
end
# command "sql", "Send sql over AR." do |query|
# if Rails.env || defined?(Rails)
# pp ActiveRecord::Base.connection.select_all(query)
# else
# pp "Pry did not require the environment, try `pconsole`"
# end
# end
# 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
# Defined aliases
Pry.config.commands.alias_command "c", "clear"
# Use Hirb gem with Pry
begin
require 'hirb'
rescue LoadError
# Missing goodies, bummer
end
if defined? Hirb
# Slightly dirty hack to fully support in-session Hirb.disable/enable toggling
Hirb::View.instance_eval do
def enable_output_method
@output_method = true
@old_print = Pry.config.print
Pry.config.print = proc do |output, value|
Hirb::View.view_or_page_output(value) || @old_print.call(output, value)
end
end
def disable_output_method
Pry.config.print = @old_print
@output_method = nil
end
end
Hirb.enable
end