Skip to content

Commit

Permalink
Merge pull request lewagon#163 from tchiadeu/pryrc
Browse files Browse the repository at this point in the history
add pryrc
  • Loading branch information
ssaunier authored Aug 29, 2024
2 parents adf05d5 + 903ad73 commit 54a90f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ symlink() {

# For all files `$name` in the present folder except `*.sh`, `README.md`, `settings.json`,
# and `config`, backup the target file located at `~/.$name` and symlink `$name` to `~/.$name`
for name in aliases gitconfig irbrc rspec zprofile zshrc; do
for name in aliases gitconfig irbrc pryrc rspec zprofile zshrc; do
if [ ! -d "$name" ]; then
target="$HOME/.$name"
backup $target
Expand Down
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 54a90f9

Please sign in to comment.