-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
spaceship-section.plugin.zsh
executable file
·55 lines (45 loc) · 2.13 KB
/
spaceship-section.plugin.zsh
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
49
50
51
52
53
54
55
#
# Foobar
#
# Foobar is a supa-dupa cool tool for making you development easier.
# Link: https://www.foobar.xyz
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_FOOBAR_SHOW="${SPACESHIP_FOOBAR_SHOW=true}"
SPACESHIP_FOOBAR_ASYNC="${SPACESHIP_FOOBAR_ASYNC=true}"
SPACESHIP_FOOBAR_PREFIX="${SPACESHIP_FOOBAR_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
SPACESHIP_FOOBAR_SUFFIX="${SPACESHIP_FOOBAR_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_FOOBAR_SYMBOL="${SPACESHIP_FOOBAR_SYMBOL="😍 "}"
SPACESHIP_FOOBAR_COLOR="${SPACESHIP_FOOBAR_COLOR="yellow"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Show foobar status
# spaceship_ prefix before section's name is required!
# Otherwise this section won't be loaded.
spaceship_foobar() {
# If SPACESHIP_FOOBAR_SHOW is false, don't show foobar section
[[ $SPACESHIP_FOOBAR_SHOW == false ]] && return
# Check if foobar command is available for execution
spaceship::exists foobar || return
# Show foobar section only when there are foobar-specific files in current
# working directory.
# spaceship::upsearch utility helps finding files up in the directory tree.
local is_foobar_context="$(spaceship::upsearch foobar.conf)"
# Here glob qualifiers are used to check if files with specific extension are
# present in directory. Read more about them here:
# http://zsh.sourceforge.net/Doc/Release/Expansion.html
[[ -n "$is_foobar_context" || -n *.foo(#qN^/) || -n *.bar(#qN^/) ]] || return
local foobar_version="$(foobar --version)"
# Check if tool version is correct
[[ $foobar_version == "system" ]] && return
# Display foobar section
# spaceship::section utility composes sections. Flags are optional
spaceship::section::v4 \
--color "$SPACESHIP_FOOBAR_COLOR" \
--prefix "$SPACESHIP_FOOBAR_PREFIX" \
--suffix "$SPACESHIP_FOOBAR_SUFFIX" \
--symbol "$SPACESHIP_FOOBAR_SYMBOL" \
"$foobar_version"
}