blob: 0aa3f450a6cb851837b6b4570d2a4091dcf39eb2 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#
# Docker
#
# Docker automates the repetitive tasks of setting up development environments
# Link: https://www.docker.com
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_DOCKER_SHOW="${SPACESHIP_DOCKER_SHOW=true}"
SPACESHIP_DOCKER_PREFIX="${SPACESHIP_DOCKER_PREFIX="on "}"
SPACESHIP_DOCKER_SUFFIX="${SPACESHIP_DOCKER_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_DOCKER_SYMBOL="${SPACESHIP_DOCKER_SYMBOL="🐳 "}"
SPACESHIP_DOCKER_COLOR="${SPACESHIP_DOCKER_COLOR="cyan"}"
SPACESHIP_DOCKER_VERBOSE="${SPACESHIP_DOCKER_VERBOSE=false}"
# ------------------------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------------------------
source "$SPACESHIP_ROOT/sections/docker_context.zsh"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Show current Docker version and connected machine
spaceship_docker() {
[[ $SPACESHIP_DOCKER_SHOW == false ]] && return
spaceship::exists docker || return
# Better support for docker environment vars: https://docs.docker.com/compose/reference/envvars/
local compose_exists=false
if [[ -n "$COMPOSE_FILE" ]]; then
# Use COMPOSE_PATH_SEPARATOR or colon as default
local separator=${COMPOSE_PATH_SEPARATOR:-":"}
# COMPOSE_FILE may have several filenames separated by colon, test all of them
local filenames=("${(@ps/$separator/)COMPOSE_FILE}")
for filename in $filenames; do
if [[ ! -f $filename ]]; then
compose_exists=false
break
fi
compose_exists=true
done
# Must return if COMPOSE_FILE is present but invalid
[[ "$compose_exists" == false ]] && return
fi
local docker_context="$(spaceship_docker_context)"
# Show Docker status only for Docker-specific folders or when connected to external host
[[ "$compose_exists" == true || -f Dockerfile || -f docker-compose.yml || -f /.dockerenv || -n $docker_context ]] || return
# if docker daemon isn't running you'll get an error saying it can't connect
# Note: Declaration and assignment is separated for correctly getting the exit code
local 'docker_version'
docker_version=$(docker version -f "{{.Server.Version}}" 2>/dev/null)
[[ $? -ne 0 || -z $docker_version ]] && return
[[ $SPACESHIP_DOCKER_VERBOSE == false ]] && docker_version=${docker_version%-*}
spaceship::section \
"$SPACESHIP_DOCKER_COLOR" \
"$SPACESHIP_DOCKER_PREFIX" \
"${SPACESHIP_DOCKER_SYMBOL}v${docker_version}${docker_context}" \
"$SPACESHIP_DOCKER_SUFFIX"
}
|