A better Pry prompt for the Rails console
2 min read
Update: This is now part of pry-rails.
On any given day I find myself with at least 2 rails consoles open at the same time. One for local development and one for the testing or production environment. All share the same prompt.
It would be really good to know what environment each rails console is operating on. While it is printed on the start of the rails console session, it usually quickly scrolls off the screen.
What if we accidentally removed the users on the wrong system? Sure, everyone has working backups, database replication and is also testing them regulary, right?
Even if we have working backups, we can still work on preventing accidents. Luckily we have complete control over the pry prompt through the
.pryrc configuration file.
A closer look at the documentation shows that we can easily make text bold and colored in the prompt:
We get the project name using:
The pry prompt can be overriden in the
.pryrc with a custom proc:
Using the above, this is what I am using for all my personal and work projects:
Here is what it looks like:
12 Feb 2017