Last active
July 17, 2025 08:02
-
-
Save justin808/1fe1dfbecc00a18e7f2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See https://github.com/justin808/justin808-dotfiles/blob/master/home/.pryrc | |
| # Using these pry gems | |
| # Essentials | |
| # gem "pry" | |
| # gem "pry-rails" | |
| # gem "pry-byebug" | |
| # gem "pry-doc" | |
| # gem "pry-rescue" | |
| # If you like this one: | |
| # gem "pry-state" | |
| # Probably not so necessary | |
| # gem "pry-toys" | |
| # Do not use pry-stack_explorer as it conflicts with pry-byebug | |
| # Pry::Commands.block_command "noconflict", "Rename step to sstep and next to nnext" do | |
| # Pry::Commands.rename_command("nnext", "next") | |
| # Pry::Commands.rename_command("bbreak", "break") | |
| # end | |
| # Pry::Commands.block_command "unnoconflict", "Revert to normal next and break" do | |
| # Pry::Commands.rename_command("next", "nnext") | |
| # Pry::Commands.rename_command("break", "bbreak") | |
| # end | |
| ## Useful Collections | |
| def a_array | |
| (1..6).to_a | |
| end | |
| def a_hash | |
| {hello: "world", free: "of charge"} | |
| end | |
| ## Benchmarking | |
| # Inspired by <http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123834#123834>. | |
| def do_time(repetitions = 100, &block) | |
| require 'benchmark' | |
| Benchmark.bm{|b| b.report{repetitions.times(&block)}} | |
| end | |
| Pry.config.color = true | |
| # New version of pry uses Pry::Prompt[:nav] | |
| unless defined?(Pry::Prompt) | |
| Pry.config.prompt = Pry::NAV_PROMPT | |
| end | |
| Pry.config.commands.alias_command "h", "hist -T 20", desc: "Last 20 commands" | |
| Pry.config.commands.alias_command "hg", "hist -T 20 -G", desc: "Up to 20 commands matching expression" | |
| Pry.config.commands.alias_command "hG", "hist -G", desc: "Commands matching expression ever used" | |
| Pry.config.commands.alias_command "hr", "hist -r", desc: "hist -r <command number> to run a command" | |
| if defined?(PryByebug) | |
| def pry_debug | |
| puts "You can also call 'pd' to save typing!" | |
| pd | |
| end | |
| def pp(obj) | |
| Pry::ColorPrinter.pp(obj) | |
| end | |
| # Shortcut for calling pry_debug | |
| def pd | |
| Pry.commands.alias_command 't', 'backtrace' | |
| Pry.commands.alias_command 's', 'step' | |
| Pry.commands.alias_command 'n', 'next' | |
| Pry.commands.alias_command 'c', 'continue' | |
| Pry.commands.alias_command 'f', 'finish' | |
| Pry.commands.alias_command 'u', 'up' | |
| Pry.commands.alias_command 'd', 'down' | |
| Pry.commands.alias_command 'b', 'break' | |
| Pry.commands.alias_command 'w', 'whereami' | |
| puts "Installed debugging Shortcuts" | |
| puts 'w : whereami' | |
| puts 's : step' | |
| puts 'n : next' | |
| puts 'c : continue' | |
| puts 'f : finish' | |
| puts 'pp(obj) : pretty print object' | |
| puts '' | |
| puts 'Stack movement' | |
| puts 't : backtrace' | |
| puts 'ff : frame' | |
| puts 'u : up' | |
| puts 'd : down' | |
| puts 'b : break' | |
| "" | |
| end | |
| # def pry_rails | |
| # puts "You can also call 'pr' to save typing!" | |
| # pr | |
| # end | |
| # # Shortcut for calling pry_debug | |
| # def pr | |
| # # Seems these are now loaded automatically in newer Rails | |
| # # require 'factory_bot'; | |
| # # FactoryBot.find_definitions | |
| # puts "Added factory support" | |
| # end | |
| # Longer shortcuts that don't conflict | |
| Pry.commands.alias_command 'ff', 'frame' | |
| Pry.commands.alias_command 'ss', 'step' | |
| Pry.commands.alias_command 'nn', 'next' | |
| Pry.commands.alias_command 'cc', 'continue' | |
| Pry.commands.alias_command 'fin', 'finish' | |
| Pry.commands.alias_command 'uu', 'up' | |
| Pry.commands.alias_command 'dd', 'down' | |
| Pry.commands.alias_command 'bb', 'break' | |
| Pry.commands.alias_command 'ww', 'whereami' | |
| end | |
| begin | |
| require 'awesome_print' | |
| # Pry.config.print = proc { |output, value| output.puts value.ai } | |
| AwesomePrint.pry! | |
| rescue LoadError => err | |
| puts "no awesome_print :(" | |
| end | |
| my_hook = Pry::Hooks.new.add_hook(:before_session, :add_dirs_to_load_path) do | |
| # adds the directories /spec and /test directories to the path if they exist and not already included | |
| dir = `pwd`.chomp | |
| dirs_added = [] | |
| %w(spec test presenters lib).map{ |d| "#{dir}/#{d}" }.each do |p| | |
| if File.exist?(p) && !$:.include?(p) | |
| $: << p | |
| dirs_added << p | |
| end | |
| end | |
| puts "Added #{ dirs_added.join(", ") } to load path in ~/.pryrc." if dirs_added.present? | |
| end | |
| # Hit Enter to repeat last command | |
| Pry::Commands.command /^$/, "repeat last command" do | |
| _pry_.run_command Pry.history.to_a.last | |
| end | |
| my_hook.exec_hook(:before_session) | |
| puts "Loaded ~/.pryrc" | |
| puts | |
| def more_help | |
| puts "Helpful shortcuts:" | |
| puts "hh : hist -T 20 Last 20 commands" | |
| puts "hg : hist -T 20 -G Up to 20 commands matching expression" | |
| puts "hG : hist -G Commands matching expression ever used" | |
| puts "hr : hist -r hist -r <command number> to run a command" | |
| puts | |
| puts "Samples variables" | |
| puts "a_array : [1, 2, 3, 4, 5, 6]" | |
| puts "a_hash : { hello: \"world\", free: \"of charge\" }" | |
| puts | |
| puts "helper : Access Rails helpers" | |
| puts "app : Access url_helpers" | |
| puts | |
| puts "require \"rails_helper\" : To include Factory Girl Syntax" | |
| puts "include FactoryGirl::Syntax::Methods : To include Factory Girl Syntax" | |
| puts | |
| puts "or if you defined one..." | |
| puts "require \"pry_helper\"" | |
| puts | |
| puts "Sidekiq::Queue.new.clear : To clear sidekiq" | |
| puts "Sidekiq.redis { |r| puts r.flushall } : Another clear of sidekiq" | |
| puts | |
| puts "Debugging Shortcuts" | |
| puts 'ss : step' | |
| puts 'nn : next' | |
| puts 'cc : continue' | |
| puts 'fin : finish' | |
| puts 'uu : up' | |
| puts 'dd : down' | |
| puts 'bb : break' | |
| puts 'w : whereami' | |
| puts 'ff : frame' | |
| puts 't : backtrace' | |
| puts '$ : show whole method of context' | |
| puts | |
| puts "Run 'pry_debug' or 'pd' to display shorter debug shortcuts" | |
| # puts "Run 'pry_rails' or 'pr' run rails helpers" | |
| puts "Run `require 'factory_girl'; FactoryBot.find_definitions` for FactoryBot" | |
| "" | |
| end | |
| puts "Run 'more_help' to see tips" |
Tip: Run help alias
Aliases
!!! Alias for `exit-program`
!!@ Alias for `exit-all`
$ Alias for `show-source`
? Alias for `show-doc`
@ Alias for `whereami`
bb Alias for `break`
breakpoint Alias for `break`
cc Alias for `continue`
clipit Alias for `gist --clip`
dd Alias for `down`
ff Alias for `frame`
file-mode Alias for `shell-mode`
fin Alias for `finish`
find-routes Alias for `find-route`
h Last 20 commands
hG Commands matching expression ever used
hg Up to 20 commands matching expression
history Alias for `hist`
hr Hist -r <command number> to run a command
nn Alias for `next`
quit Alias for `exit`
quit-program Alias for `exit-program`
reload-method Alias for `reload-code`
show-method Alias for `show-source`
ss Alias for `step`
uu Alias for `up`
ww Alias for `whereami`
Gems I use for Pry:
See comment at top of gist.
See: http://forum.shakacode.com/t/my-pryrc-for-debugging-and-productivity/364
Comment on line 44 should say break/bbreak instead of step/sstep
@dkassen, Thanks for the tip. I can't figure out why I needed those blocks. Any idea?
@justin808 break and next seem like standard debugger commands, there might be some other settings that modify or add those commands. I’m guessing pry keeps a registry of commands and renaming them like this seems like it’d override any other definitions. Seems hacky.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great Job! Thanks.