DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Command Aliases for Ruby Debug
Sven Schwyn
Sven Schwyn

Posted on

Command Aliases for Ruby Debug

After years with Pry, there's a new old kid on the block now: debug.rb >=1.0.0 – all new, shiny and ready for Ruby 3.

One thing I miss though is the ability to create command aliases.

To quickly get out of the debugger, typing Β«exit-programΒ» involves too many hands for my taste, I prefer something quick like Β«eeeΒ» instead. Pry lets you create such command aliases in ~/.pryrc:

Pry.config.commands.alias_command "eee", "exit-program"
Pry.config.commands.alias_command "ee", "exit"
Enter fullscreen mode Exit fullscreen mode

Typing Β«kill!Β» or its shorter twin Β«k!Β» with debug.rb is no fun either. Here's a quick and dirty monkey patch to do a similar trick in ~/.rdbgrc.rb:

module DEBUGGER__
  class Session
    COMMAND_ALIASES = {
      'ee' => 'quit!',
      'eee' => 'kill!'
    }.freeze

    alias_method :original_process_command, :process_command
    def process_command line
      original_process_command COMMAND_ALIASES.fetch(line, line)
    end
  end
end
Enter fullscreen mode Exit fullscreen mode

Happy hammering your "e" key!


Photo by JΓΈrgen HΓ₯land on Unsplash

Top comments (0)

We want your help! Become a Tag Moderator.
Fill out this survey and help us moderate our community by becoming a tag moderator here at DEV.