Peer Allan edited this page May 11, 2017 · 21 revisions

The .pryrc file

Quick Menu:

Back to Main Menu

Overview

The .pryrc file is analogous to the .irbrc file for IRB. You can use the .pryrc file to customize Pry.

When pry starts, it checks for a .pryrc file in your home directory(~/.pryrc) and also for a per-project .pryrc in the current directory(./.pryrc). Both files are used if they exist, with the file from your home directory being loaded first.

Loading and suppression

The .pryrc files are the first files loaded after Pry is initialized but before a session starts. Notably, the .pryrc files are loaded before plugins and Readline history are loaded, giving you an opportunity to control these two features.

Suppression of .pryrc from loading:

  • Command line suppression of .pryrc: Invoke the pry executable with the the -f switch.
  • Runtime invocation and suppression of .pryrc: Ensure that you set Pry.config.should_load_rc = false before starting a session.

Example: Command line invocation and .pryrc suppression

crow:~ john$ pry -f
pry(main)>

Example: Runtime invocation and .pryrc suppression

Pry.config.should_load_rc = false
binding.pry

Back to top

Customize Pry in your .pryrc

Nearly every aspect of Pry can be customized in the .pryrc file; we can change the prompt, add command aliases, add or delete commands, disable certain plugins, configure Readline history loading, turn off colors and paging, and so on.

In the example below we import the Experimental command set, turn off paging and color, add a command alias, define a new command, turn off history saving, and change the prompt (these options explained further in the customization and commands sections):

Example:

Pry.config.commands.import Pry::ExtendedCommands::Experimental

Pry.config.pager = false

Pry.config.color = false

Pry.config.commands.alias_command "lM", "ls -M"

Pry.config.commands.command "add", "Add a list of numbers together" do |*args|
  output.puts "Result is: #{args.map(&:to_i).inject(&:+)}"
end

Pry.config.history.should_save = false

Pry.config.prompt = [proc { "input> " },
                     proc { "     | " }]

# Disable pry-buggy-plug:
Pry.plugins["buggy-plug"].disable!

Back to top

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.