Skip to content

Instantly share code, notes, and snippets.

@Intrepidd

Intrepidd/.pryrc Secret

Last active July 7, 2023 17:55
Show Gist options
  • Save Intrepidd/af2bb4ed825817ecb044a5e93fc52f4d to your computer and use it in GitHub Desktop.
Save Intrepidd/af2bb4ed825817ecb044a5e93fc52f4d to your computer and use it in GitHub Desktop.
# Add color coding based on Rails environment for safety
# edited by cveneziani
if defined? Rails
banner = if Rails.env.production? || Rails.env.staging?
"\e[41;97;1m #{Rails.env} \e[0m "
else
"\e[42;97;1m #{Rails.env} \e[0m "
end
Pry.config.prompt_name = banner
end
@cveneziani
Copy link

cveneziani commented Jan 7, 2021

Hi there,

I tried to play a bit with this snippet and if you have the same code within a ~/.pryrc and a project's .pryrc, we end up with a stack level too deep error at line 14.

What about the following code?

if defined? Rails
  banner = if Rails.env.production? || Rails.env.staging?
    "\e[41;97;1m #{Rails.env} \e[0m "
  else
    "\e[42;97;1m #{Rails.env} \e[0m "
  end

  Pry.config.prompt_name = banner
end

@Intrepidd
Copy link
Author

Bonjour 👋

Fabulous, I didn't know anything about pry prompts, your solution is much simpler, I'll update my gist !

@cveneziani
Copy link

Sam same, I didn't know about pry prompts. I discovered the prompt_name while investigating the stack level too deep 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment