-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pryrc
52 lines (45 loc) · 1.24 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
# typed: false
# frozen_string_literal: true
require "pry-doc"
require "pry-sorbet"
require "pry-stack_explorer"
require "break"
# Fix control characters.
#
# TODO: No longer necessary when https://github.com/pry/pry/pull/2209 is merged.
ENV["PAGER"] = " less --raw-control-chars -F -X"
# == Commands
Pry::Commands.block_command("clear", "Clear the screen.") do
system("clear")
end
Pry::Commands.block_command(
"copy",
"Copy argument to the system clipboard.",
) do |arg|
IO.popen("pbcopy", "w") do |f|
value = target.eval(arg)
f << value.to_s
end
end
Pry::Commands.block_command("debug", "Debug the current binding.") do
run "exit-all binding.break(pre: 'finish 38 ;; up')"
end
Pry::Commands.block_command("sql", "Perform an SQL query over AR.") do |query|
if ENV["RAILS_ENV"] || defined?(Rails)
pp(ActiveRecord::Base.connection.select_all(query))
else
pp("Error: Not in a Rails environment.")
end
end
Pry::Commands.block_command(
"caller_method",
"Show the 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