Skip to content

Commit

Permalink
add pryrc
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiadeu committed Aug 22, 2024
1 parent adf05d5 commit f9b3da1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pryrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://github.com/pry/pry/tree/master/lib/pry

if defined?(Rails)
short_env_name_options = {
'development' => 'dev',
'production' => 'prod'
}
app_name = Rails.application.class.module_parent_name.underscore.dasherize
env_name = short_env_name_options.fetch(Rails.env) { Rails.env }
description = 'Prompt has to match the rails app name'
else
current_directory = Dir.pwd.split('/').last.to_s
description = 'Prompt has to match the current directory name'
end

# https://github.com/pry/pry/blob/master/lib/pry/prompt.rb
Pry::Prompt.add(:current_app) do |context, nesting, pry_instance, sep|
format(
'[%<in_count>s] %<current_app>s(%<context>s)%<nesting>s%<separator>s ',
in_count: pry_instance.input_ring.count,
current_app: app_name || current_directory,
context: env_name || Pry.view_clip(context),
nesting: (nesting > 0 ? ":#{nesting}" : ''),
separator: sep
)
end

prompt = Pry::Prompt[:current_app]
procs = [
proc { |*args| prompt.wait_proc.call(*args).to_s },
proc { |*args| prompt.incomplete_proc.call(*args).to_s }
]

Pry.config.prompt = Pry::Prompt.new(
'custom_app_prompt', description, procs
)

0 comments on commit f9b3da1

Please sign in to comment.