DEV Community

Cover image for Command aliases for Ruby debug
Sven Schwyn
Sven Schwyn

Posted on • Updated 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)