Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds ability to customize the display name on the prompt

  • Loading branch information...
commit 483493e340dae56420a7531fd4b6779897041f8f 1 parent 3203f00
@datapimp datapimp authored
Showing with 17 additions and 6 deletions.
  1. +8 −6 lib/pry.rb
  2. +8 −0 lib/pry/config.rb
  3. +1 −0  lib/pry/pry_class.rb
View
14 lib/pry.rb
@@ -61,14 +61,16 @@ class Pry
# Don't catch these exceptions
DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException]
+ DEFAULT_PROMPT_NAME = 'pry'
+
# The default prompt; includes the target and nesting level
DEFAULT_PROMPT = [
proc { |target_self, nest_level, pry|
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
+ "[#{pry.input_array.size}] #{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
},
proc { |target_self, nest_level, pry|
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
+ "[#{pry.input_array.size}] #{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
}
]
@@ -76,8 +78,8 @@ class Pry
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
SHELL_PROMPT = [
- proc { |target_self, _, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
- proc { |target_self, _, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
+ proc { |target_self, _, _| "#{Pry.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
+ proc { |target_self, _, _| "#{Pry.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
]
# A prompt that includes the full object path as well as
@@ -85,11 +87,11 @@ class Pry
NAV_PROMPT = [
proc do |conf|
tree = conf.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
- "[#{conf.expr_number}] (pry) #{tree}: #{conf.nesting_level}> "
+ "[#{conf.expr_number}] (#{Pry.config.prompt_name}) #{tree}: #{conf.nesting_level}> "
end,
proc do |conf|
tree = conf.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
- "[#{conf.expr_number}] (pry) #{tree}: #{conf.nesting_level}* "
+ "[#{conf.expr_number}] (#{ Pry.config.prompt_name}) #{tree}: #{conf.nesting_level}* "
end,
]
View
8 lib/pry/config.rb
@@ -112,6 +112,14 @@ def hooks=(v)
# Pry.config.prompt = proc { |obj, nest_level, _pry_| "#{obj}:#{nest_level}> " }
attr_accessor :prompt
+ # The display name that is part of the prompt. Default is 'pry'.
+ # You can set your own name so you can identify which project your current pry session
+ # is using. This is useful if you have a local pryrc file in a Rails project for example.
+ # @return [String]
+ # @example
+ # Pry.config.prompt_name = 'my_rails_project'
+ attr_accessor :prompt_name
+
# The default editor to use. Defaults to $VISUAL, $EDITOR, or a sensible fallback
# for the platform.
# If `editor` is a String then that string is used as the shell
View
1  lib/pry/pry_class.rb
@@ -244,6 +244,7 @@ def self.set_config_defaults
config.input = Readline
config.output = $stdout
config.commands = Pry::Commands
+ config.prompt_name = DEFAULT_PROMPT_NAME
config.prompt = DEFAULT_PROMPT
config.print = DEFAULT_PRINT
config.exception_handler = DEFAULT_EXCEPTION_HANDLER
Please sign in to comment.
Something went wrong with that request. Please try again.