How to show your current Firebase project name on the command line prompt to prevent dangerous errors
BlockedUnblockFollowFollowing
When working on a project with multiple stages (development, staging, production), developers use the command firebase use
to switch between projects. It’s very easy to run a command on the production environment instead of the development. This is very dangerous.
Note: You can always find the latest script at my GitHub repository.
Normally, developers only work on the development project. They only switch to production in case of checking or doing a hotfix. There have been a few times when I forgot to switch back to the development project. I accidentally changed the database without thinking that it could impact the actual users.
Digging into the firebase CLI, I found that it uses configstore to manage local configuration. All config is saved in a JSON file and reads easily. I created a small script which is intended to show the firebase project name on shell prompt.
How to set it up
Bash
Add the following script to the end of ~/.bash_profile
:
Then run source ~/.bash_profile
or open a new terminal window:
iTerm2 with oh-my-zsh
Oh-my-zsh is a popular open source framework for Zshell. I like it because it has many beautiful terminal themes and many useful plugins.
Here, I will make an example with the agnoster theme:
Edit ~/.oh-my-zsh/themes/agnoster.zsh-theme
and then add prompt_firebase
to build_prompt
functions:
For the final step, run source ~/.zshrc
or open a new terminal window:
I hope this can help you prevent the an unexpected (and bad) situation.
Note: You can always find the latest script at my GitHub repository.