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

Firebase project prompt section #1158

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions sections/firebase.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_FIREBASE_SHOW="${SPACESHIP_FIREBASE_SHOW=true}"
SPACESHIP_FIREBASE_PREFIX="${SPACESHIP_FIREBASE_PREFIX="FB project: "}"
SPACESHIP_FIREBASE_SYMBOL="${SPACESHIP_FIREBASE_SYMBOL="🔥 "}"
SPACESHIP_FIREBASE_COLOR="${SPACESHIP_FIREBASE_COLOR="#d75f00"}"

# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------

# Shows active Firebase Project
spaceship_firebase() {

# wheather to show this section
[[ $SPACESHIP_FIREBASE_SHOW == false ]] && return

# check if firebase-tools cli is installed
spaceship::exists firebase || return

# firebase-cli creates this config file with all the settings
local file=~/.config/configstore/firebase-tools.json
if [ ! -f "$file" ]; then
return
fi
local currentDir=$(pwd)
# big thanks to https://github.com/jozefcipa/zsh-firebase-prompt for the actual implementation
current_project=$(
cat $file |
jq --arg currentDir $currentDir '
[
.activeProjects
| to_entries[]
| .key as $key
| select($currentDir | startswith($key))
] | [
sort_by(.key | length)
| reverse[]
] | .[0].value'
)

if [ "$current_project" != "null" ]; then
# remove the quotations
current_project=$(echo $current_project | awk '{gsub(/[\"]/, "", $1)} {print $1" "}')

spaceship::section \
--color "$SPACESHIP_FIREBASE_COLOR" \
--prefix "$SPACESHIP_FIREBASE_PREFIX" \
"${SPACESHIP_FIREBASE_SYMBOL}${current_project}"
fi
}
2 changes: 1 addition & 1 deletion tests/shunit2
Submodule shunit2 updated 1 files
+1 −26 shunit2_misc_test.sh