diff --git a/sections/firebase.zsh b/sections/firebase.zsh new file mode 100644 index 000000000..1ba0af8d7 --- /dev/null +++ b/sections/firebase.zsh @@ -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 +} diff --git a/tests/shunit2 b/tests/shunit2 index 3334e5304..47be8b23a 160000 --- a/tests/shunit2 +++ b/tests/shunit2 @@ -1 +1 @@ -Subproject commit 3334e53047ad143669870a9c223b70a81156533a +Subproject commit 47be8b23a46a7897e849f1841f0fb704d34d0f6e