├── LICENSE ├── README.md └── firebase.plugin.zsh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Seqi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # firebase-zsh :fire: 2 | 3 | [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 4 | 5 | firebase-zsh is a configurable plugin for Zsh to display the current working project or project alias when in a Firebase project directory or subdirectory. Never push to production accidentally again! 6 | 7 | Part of the [Awesome zsh plugins collection!](https://github.com/unixorn/awesome-zsh-plugins) 8 | 9 | ![](https://i.imgur.com/wGwuTH7.png) 10 | 11 | ## Installation 12 | 13 | Clone the repository into your oh-my-zsh plugin folder: 14 | 15 | `git clone https://github.com/seqi/firebase-zsh ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/firebase` 16 | 17 | Then add it to your list of plugins in your `~/.zshrc` 18 | 19 | `plugins=(git firebase)` 20 | 21 | Finally, add the plugin output to your prompt, by opening your theme and adding the firebase project. 22 | 23 | For example, 24 | 25 | `PROMPT='%{$fg[cyan]%}%n%{$reset_color%}:$(git_prompt_info) %(!.#.$) '` 26 | 27 | becomes 28 | 29 | `PROMPT='%{$fg[cyan]%}%n%{$reset_color%}:$(firebase_project) $(git_prompt_info)%(!.#.$) '` 30 | 31 | Restart Zsh for the changes to take effect. 32 | 33 | ## Configuration 34 | 35 | firebase-zsh has a few customisation options to get it to fit with whatever theme you are using. These can be configured through environment variables. These options are: 36 | 37 | ### `FIREBASE_ZSH_TEXT` 38 | Configures the font style of the text. 39 | 40 | Options: 41 | - `bold` - makes the text bold 42 | 43 | Defaults to **non-bold** 44 | 45 | ### `FIREBASE_ZSH_ICON` 46 | Whether or not to show the 🔥 icon. 47 | 48 | Options: 49 | - `true` 50 | 51 | Defaults to **false** 52 | 53 | ### `FIREBASE_ZSH_STYLE` 54 | The format of the text itself to help match with your current zsh theme. 55 | 56 | Options: 57 | - `plain`: output as `my-firebase-project` 58 | - `round`: output as `(my-firebase-project)` 59 | - `square`: output as `[my-firebase-project]` 60 | - `prefix`: output as `fb:my-firebase-project` 61 | - `prefix-round`: output as `fb:(my-firebase-project)` 62 | - `prefix-square`: output as `fb:[my-firebase-project]` 63 | 64 | Defaults to **round** 65 | 66 | ### `FIREBASE_ZSH_TRAILING_SPACE` 67 | Adds a trailing space to the output. 68 | 69 | ### `FIREBASE_ZSH_LEADING_SPACE` 70 | Adds a leading space to the output. 71 | 72 | ## Contributing 73 | 74 | Changes are welcomed. If you have an issue, please feel free to raise it in the issues section. If you wish to make a contribution, please create a corresponding issue. 75 | 76 | ## License 77 | [MIT](https://choosealicense.com/licenses/mit/) 78 | -------------------------------------------------------------------------------- /firebase.plugin.zsh: -------------------------------------------------------------------------------- 1 | function firebase_project() { 2 | local project_id=$(get_firebase_project) 3 | 4 | if [[ -n $project_id ]] 5 | then 6 | ## Set color 7 | [[ "$FIREBASE_ZSH_TEXT" = "bold" ]] && color=$fg_bold[yellow] || color=$fg[yellow] 8 | 9 | local fire="\U1F525" 10 | if [[ "$FIREBASE_ZSH_ICON" == "true" ]] 11 | then 12 | project_id="$fire $project_id" 13 | fi 14 | 15 | project_id=$(decorate_str "$project_id" "$FIREBASE_ZSH_STYLE") 16 | 17 | ### Set Prompt ### 18 | project_id="%{$color%}"$project_id"%{$reset_color%}" 19 | 20 | # Add trailing space 21 | if [[ "$FIREBASE_ZSH_TRAILING_SPACE" == "true" ]] 22 | then 23 | echo "$project_id " 24 | elif [[ "$FIREBASE_ZSH_LEADING_SPACE" == "true" ]] 25 | then 26 | echo " $project_id" 27 | else 28 | echo $project_id 29 | fi 30 | fi 31 | } 32 | 33 | function decorate_str() { 34 | local project_id=$1 35 | local style=$2 36 | 37 | if [[ $style == 'plain' ]] 38 | then 39 | echo "$project_id" 40 | 41 | # [project] 42 | elif [[ $style == 'square' ]] 43 | then 44 | echo "[$project_id]" 45 | 46 | # fb:project 47 | elif [[ $style == 'prefix' ]] 48 | then 49 | echo "fb:$project_id" 50 | 51 | # fb:(project) 52 | elif [[ $style == 'prefix-round' ]] 53 | then 54 | echo "fb:($project_id)" 55 | 56 | # fb:[project] 57 | elif [[ $style == 'prefix-square' ]] 58 | then 59 | echo "fb:[$project_id]" 60 | 61 | # (project) 62 | else 63 | echo "($project_id)" 64 | fi 65 | } 66 | 67 | function get_firebase_project() { 68 | if [[ $(is_firebase_project) ]] 69 | then 70 | # Check the global firebase config file as priority 71 | local config_project_id=$(get_config_project_id) 72 | if [[ -n $config_project_id ]] 73 | then 74 | echo "$config_project_id" 75 | 76 | # If nothing in the firebase config file, use the default value set in .firebaserc 77 | else 78 | local firebaserc_project_id=$(get_rc_project_id "default") 79 | echo "$firebaserc_project_id" 80 | fi 81 | fi 82 | } 83 | 84 | function is_firebase_project() { 85 | local firebase_dir=$(get_firebase_dir) 86 | if [[ -n $firebase_dir ]] 87 | then 88 | echo 1 89 | fi 90 | } 91 | 92 | function get_firebase_dir() { 93 | local dir="$(pwd)" 94 | 95 | # Keep checking up, we may be in a subdir 96 | while [[ $dir != '/' ]] 97 | do 98 | local target="$dir/firebase.json" 99 | 100 | if [[ -e $target ]] 101 | then 102 | echo $dir 103 | break 104 | else 105 | dir=$(dirname ${dir:A}) 106 | fi 107 | done 108 | } 109 | 110 | function get_config_project_id() { 111 | if [[ -e ~/.config/configstore/firebase-tools.json ]] 112 | then 113 | # May be either the project id itself or an alias (which lives in .firebaserc) 114 | local target=$(get_firebase_dir) 115 | echo $(grep -s $target ~/.config/configstore/firebase-tools.json | cut -d'"' -f 4) 116 | fi 117 | } 118 | 119 | function get_rc_project_id() { 120 | local rc_path="$(get_firebase_dir)/.firebaserc" 121 | echo $(grep $1 $rc_path | cut -d'"' -f 4) 122 | } --------------------------------------------------------------------------------