Last active
December 7, 2020 14:17
-
-
Save jsugarman/aad9566ad6d615bdd6203b363c330b7b to your computer and use it in GitHub Desktop.
Custom pry with command aliases and custom rails prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place in ~/.pryrc | |
if defined?(Pry) | |
Pry.config.color = true | |
Pry.config.prompt_name = 'Pry:' + File.basename(Dir.pwd) | |
Pry.commands.alias_command 'wami', 'whereami' | |
Pry.commands.alias_command 'c', 'continue' | |
Pry.commands.alias_command 's', 'step' | |
Pry.commands.alias_command 'n', 'next' | |
Pry.commands.alias_command 'f', 'finish' | |
Pry.commands.alias_command 'dp', 'disable-pry' | |
def rails_formatted_env | |
case Rails.env | |
when 'production' | |
bold_upcased_env = Pry::Helpers::Text.red(Rails.env.upcase) | |
Pry::Helpers::Text.red(bold_upcased_env) | |
when 'development', 'test', 'staging' | |
Pry::Helpers::Text.yellow(Rails.env) | |
else | |
Rails.env | |
end | |
end | |
# This may need to be adjusted for Rails < 4 | |
def rails_app_name | |
Rails.application.class.module_parent.name.underscore | |
end | |
Pry::Prompt.add( | |
:custom_rails, | |
'A prompt that displays Rails app name and env', | |
%w[> *] | |
) do |context, _nesting, pry_instance, sep| | |
format( | |
"%<in_count>s: %<app_name>s(%<env>s) %<separator>s ", | |
in_count: pry_instance.input_ring.count, | |
app_name: rails_app_name, | |
env: rails_formatted_env, | |
separator: sep | |
) | |
end | |
# You can set prompt here or in a session | |
# - see change-prompt -l | |
# :none, :shell, :default, :simple, :rails, custom_rails | |
# | |
Pry.config.prompt = Pry::Prompt[:custom_rails] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment