From 19c6d2beeae782989be2b640b7f271f0f8498284 Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Mon, 3 Jul 2023 14:35:20 -0300 Subject: [PATCH] Add env to the rails console --- .irbrc | 16 ++++++++++++++++ .pryrc | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 .irbrc diff --git a/.irbrc b/.irbrc new file mode 100644 index 00000000..f48fec60 --- /dev/null +++ b/.irbrc @@ -0,0 +1,16 @@ +# Add color coding based on Rails environment for safety +if defined?(Rails) + banner = if Rails.env.production? + "\e[41;97;1m #{Rails.env} \e[0m " + else + "\e[42;97;1m #{Rails.env} \e[0m " + end + + # Build a custom prompt + IRB.conf[:PROMPT][:CUSTOM] = IRB.conf[:PROMPT][:DEFAULT].merge( + PROMPT_I: banner + IRB.conf[:PROMPT][:DEFAULT][:PROMPT_I] + ) + + # Use custom prompt by default + IRB.conf[:PROMPT_MODE] = :CUSTOM +end diff --git a/.pryrc b/.pryrc index 705f61f6..f882b27b 100644 --- a/.pryrc +++ b/.pryrc @@ -1,6 +1,18 @@ +# Add command aliases if defined?(PryByebug) Pry.commands.alias_command 'c', 'continue' Pry.commands.alias_command 's', 'step' Pry.commands.alias_command 'n', 'next' Pry.commands.alias_command 'f', 'finish' end + +# Add color coding based on Rails environment for safety +if defined?(Rails) && defined?(Pry) + banner = if Rails.env.production? + "\e[41;97;1m #{Rails.env} \e[0m " + else + "\e[42;97;1m #{Rails.env} \e[0m " + end + + Pry.config.prompt_name = banner +end