Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: rename Rails console as irr or something other than irb #50770

Closed
MtnBiker opened this issue Jan 16, 2024 · 23 comments · Fixed by #50796
Closed

Request: rename Rails console as irr or something other than irb #50770

MtnBiker opened this issue Jan 16, 2024 · 23 comments · Fixed by #50796

Comments

@MtnBiker
Copy link

Maybe not the right place to post this.

But it's confusing that the prompt for irb and rails console is the same.

@Edouard-chin
Copy link
Member

You can create a ~/.irbrc file and customize irb as you wish here. You can use something like this:

if ENV["RAILS_ENV"]
  IRB.conf[:PROMPT][:RAILS] = IRB.conf[:PROMPT][:DEFAULT].clone
  IRB.conf[:PROMPT][:RAILS][:PROMPT_I] = "%N(rails):%03n> "

  IRB.conf[:PROMPT_MODE] = :RAILS
end

@Edouard-chin Edouard-chin closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
@MtnBiker
Copy link
Author

Thanks. Works like a charm.

@rafaelfranca
Copy link
Member

Maybe we should do that automatically. @dhh what do you think?

@dhh
Copy link
Member

dhh commented Jan 16, 2024

What's the problem we're trying to solve?

@dhh
Copy link
Member

dhh commented Jan 16, 2024

Why is it an issue that the prompt is the same between vanilla irb and irb loaded with the Rails app? That's the first time I've heard of that causing someone problems.

@rafaelfranca
Copy link
Member

I believe because of the methods available in Rails console are drastically different from just calling irb so if you have two terminals one with the console another one with the irb, you don't know where you are at. I have seeing people also changing the prompt to show if the console is a production console.

In general, I think it would be good developer experience to Rails to show a more informative prompt.

@dhh
Copy link
Member

dhh commented Jan 16, 2024

Yeah, I could be on for making it more informative. Like including the env. But also don't want to make the line too long. Don't think adding (rails) to it is meaningful.

@MtnBiker
Copy link
Author

Length: irb(rails):002> vs irb(main):001> using @Edouard-chin Edouard-chin. They are the same in the two places I use it.

Maybe irc(main) for rails console and irb(main) as it has been.

They are different environments and shouldn't look the same.

@dhh
Copy link
Member

dhh commented Jan 17, 2024

Actually, if anything, we should shave off the needless prefixing. "irb(main):001>" is just noise for us. But I'd take "dev:001>" and "prod:001>". Problem is we don't have any structured abbreviated names for envs. You don't want "development:001>" and "production:001>". Too long.

@MtnBiker
Copy link
Author

An example of where confusion can arise. In Active Record Query Interface, Section 2.1.1, the following example irb> customer = Customer.find(10) appears. The word console appears no where on that page. I think some will think irb means irb, not rails console.

@Edouard-chin
Copy link
Member

Oops, looks like I closed this too early and there is more to it, sorry!
I don't have much opinion on the topic.

You don't want "development:001>" and "production:001>". Too long.

For reference, the prompt name on a postgres repl is the name of the database, which never bothered me and felt it was too long. 🤷

❯ bin/rails dbconsole

my_app_development=#

@Edouard-chin Edouard-chin reopened this Jan 17, 2024
@st0012
Copy link
Contributor

st0012 commented Jan 17, 2024

Just to add some ideas and notes:

  • You can use IRB.conf[:IRB_NAME] to replace irb from the prompt more easily.
    • For example, IRB.conf[:IRB_NAME] = Rails.root.basename.to_s will give you
      my-app(main):001>
  • IRB has colorisation module that can also be used here.
    • IRB.conf[:IRB_NAME] = IRB::Color.colorize(Rails.root.basename.to_s, [:BLUE, :BOLD]) will show my-app in blue and the rest in the default colour.
    • Displaying different environments in different colours may be helpful as I've seen a few apps showing production in red.
  • The way Rails currently invokes IRB doesn't allow it to use IRB.conf for configuration. So if we decided to customise the prompt, some additional adjustments need to be made there too. I'll be happy to help on this :-)

@rafaelfranca
Copy link
Member

@st0012 can we move forward with "dev:001>" and "prod:001>"?

@st0012
Copy link
Contributor

st0012 commented Jan 18, 2024

@rafaelfranca sure no problem. I'll prepare a PR for it.

@byroot
Copy link
Member

byroot commented Jan 20, 2024

"dev:001>" and "prod:001>"?

Is the 001 even worth it? I don't quite see the value of it. My irbrc just strips it.

@dhh
Copy link
Member

dhh commented Jan 20, 2024

Agree, I'd rather do without.

@st0012
Copy link
Contributor

st0012 commented Jan 20, 2024

Maybe the saved space could display the app/folder name, like dev:my-app> or my-app(dev)>?

@byroot
Copy link
Member

byroot commented Jan 20, 2024

I think the application name would be valuable yes, especially for people who often juggle between multiple applications.

My preference goes to my-app(dev)> but no strong opinion here.

@dhh
Copy link
Member

dhh commented Jan 20, 2024

Dig that a lot 👌

st0012 added a commit to Shopify/rails that referenced this issue Jan 20, 2024
Following the discussion in rails#50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored with green.
st0012 added a commit to Shopify/rails that referenced this issue Jan 20, 2024
Following the discussion in rails#50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored.
@st0012
Copy link
Contributor

st0012 commented Jan 20, 2024

PR for the prompt change: #50825

st0012 added a commit to Shopify/rails that referenced this issue Jan 20, 2024
Following the discussion in rails#50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored.

Update railties/lib/rails/commands/console/console_command.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

Update changelog
@dorianmariecom
Copy link
Contributor

Wouldn't development and production be more consistent with the rest of the usage in rails?

@ghiculescu
Copy link
Member

I think the application name would be valuable yes, especially for people who often juggle between multiple applications.

My preference goes to my-app(dev)> but no strong opinion here.

Would you consider adding the Rails version to the prompt?

Eg. my-app @ 7.1.1(dev)>

We've found it handy when doing upgrades, or switching between apps on different versions.

@dhh
Copy link
Member

dhh commented Jan 28, 2024

Too much for me. But great to point someone at how they can customize this further.

Context > Consistency on prod/dev. I don't want a long prefacing line. It's just ugly.

viralpraxis pushed a commit to viralpraxis/rails that referenced this issue Mar 24, 2024
Following the discussion in rails#50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored.

Update railties/lib/rails/commands/console/console_command.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants