-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-section
executable file
·48 lines (44 loc) · 1.58 KB
/
firebase-section
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
# SPACESHIP_FIREBASE_SHOW="${SPACESHIP_FIREBASE_SHOW=true}"
# SPACESHIP_FIREBASE_PREFIX="${SPACESHIP_FIREBASE_PREFIX="FB project: "}"
# SPACESHIP_FIREBASE_SYMBOL="${SPACESHIP_FIREBASE_SYMBOL="🔥"}"
SPACESHIP_FIREBASE_SYMBOL="🔥"
# SPACESHIP_FIREBASE_COLOR="${SPACESHIP_FIREBASE_COLOR="#d75f00"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Shows active Firebase Project
firebase_section() {
# check if firebase-tools cli is installed
local firebase_cli=$(which firebase)
if [ ! -f "$firebase_cli" ]; then
return
fi
# 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" "}')
echo "$SPACESHIP_FIREBASE_SYMBOL$current_project"
fi
}