Add docker_context segment

Adds docker_context segment to show current docker context, with
SHOW_ON_COMMAND and SHOW_DEFAULT parameters.

Closes #1485
This commit is contained in:
Eli Treuherz 2021-11-17 10:14:00 +00:00
parent a9f208c8fc
commit 4dea8c7a08
6 changed files with 60 additions and 0 deletions

View file

@ -68,6 +68,7 @@
phpenv # php version from phpenv (https://github.com/phpenv/phpenv)
scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv)
haskell_stack # haskell version from stack (https://haskellstack.org/)
docker_context # current docker context (https://docs.docker.com/engine/context/working-with-contexts/)
kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io)
# terraform_version # terraform version (https://www.terraform.io)
@ -1212,6 +1213,13 @@
# Custom icon.
# typeset -g POWERLEVEL9K_TERRAFORM_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐'
#############[ docker_context: current docker context (https://docs.docker.com/engine/context/working-with-contexts/) ]#############
# Show docker context only when the command you are typing invokes one of these (pipe-separated) tools.
# Comment the next line to always show docker context.
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_ON_COMMAND='docker'
# Don't show docker context if it's literally "default".
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT=false
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Show kubecontext only when the the command you are typing invokes one of these tools.
# Tip: Remove the next line to always show kubecontext.

View file

@ -68,6 +68,7 @@
phpenv # php version from phpenv (https://github.com/phpenv/phpenv)
scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv)
haskell_stack # haskell version from stack (https://haskellstack.org/)
docker_context # current docker context (https://docs.docker.com/engine/context/working-with-contexts/)
kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io)
# terraform_version # terraform version (https://www.terraform.io)
@ -1154,6 +1155,13 @@
# Custom icon.
# typeset -g POWERLEVEL9K_HASKELL_STACK_VISUAL_IDENTIFIER_EXPANSION='⭐'
#############[ docker_context: current docker context (https://docs.docker.com/engine/context/working-with-contexts/) ]#############
# Show docker context only when the command you are typing invokes one of these (pipe-separated) tools.
# Comment the next line to always show docker context.
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_ON_COMMAND='docker'
# Don't show docker context if it's literally "default".
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT=false
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Show kubecontext only when the the command you are typing invokes one of these tools.
# Tip: Remove the next line to always show kubecontext.

View file

@ -68,6 +68,7 @@
phpenv # php version from phpenv (https://github.com/phpenv/phpenv)
scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv)
haskell_stack # haskell version from stack (https://haskellstack.org/)
docker_context # current docker context (https://docs.docker.com/engine/context/working-with-contexts/)
kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io)
# terraform_version # terraform version (https://www.terraform.io)
@ -1150,6 +1151,13 @@
# Custom icon.
# typeset -g POWERLEVEL9K_HASKELL_STACK_VISUAL_IDENTIFIER_EXPANSION='⭐'
#############[ docker_context: current docker context (https://docs.docker.com/engine/context/working-with-contexts/) ]#############
# Show docker context only when the command you are typing invokes one of these (pipe-separated) tools.
# Comment the next line to always show docker context.
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_ON_COMMAND='docker'
# Don't show docker context if it's literally "default".
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT=false
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Show kubecontext only when the the command you are typing invokes one of these tools.
# Tip: Remove the next line to always show kubecontext.

View file

@ -68,6 +68,7 @@
phpenv # php version from phpenv (https://github.com/phpenv/phpenv)
scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv)
haskell_stack # haskell version from stack (https://haskellstack.org/)
docker_context # current docker context (https://docs.docker.com/engine/context/working-with-contexts/)
kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io)
# terraform_version # terraform version (https://www.terraform.io)
@ -1283,6 +1284,13 @@
################[ terraform_version: It shows active terraform version (https://www.terraform.io) ]#################
typeset -g POWERLEVEL9K_TERRAFORM_VERSION_SHOW_ON_COMMAND='terraform|tf'
#############[ docker_context: current docker context (https://docs.docker.com/engine/context/working-with-contexts/) ]#############
# Show docker context only when the command you are typing invokes one of these (pipe-separated) tools.
# Comment the next line to always show docker context.
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_ON_COMMAND='docker'
# Don't show docker context if it's literally "default".
typeset -g POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT=false
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Show kubecontext only when the the command you are typing invokes one of these tools.
# Tip: Remove the next line to always show kubecontext.

View file

@ -147,6 +147,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' # ⬢
DOCKER_ICON '\U1F433' # 🐳
)
;;
'awesome-fontconfig')
@ -278,6 +279,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' # ⬢
DOCKER_ICON '\U1F433' # 🐳
)
;;
'awesome-mapped-fontconfig')
@ -412,6 +414,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' # ⬢
DOCKER_ICON '\U1F433' # 🐳
)
;;
'nerdfont-complete'|'nerdfont-fontconfig')
@ -544,6 +547,7 @@ function _p9k_init_icons() {
JULIA_ICON '\uE624' # 
SCALA_ICON '\uE737' # 
TOOLBOX_ICON '\uE20F'$s # 
DOCKER_ICON '\U1F433' # 🐳
)
;;
ascii)
@ -673,6 +677,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON 'toolbox'
DOCKER_ICON 'docker'
)
;;
*)
@ -804,6 +809,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' # ⬢
DOCKER_ICON '\U1F433' # 🐳
)
;;
esac

View file

@ -2130,6 +2130,27 @@ prompt_dir() {
instant_prompt_dir() { prompt_dir; }
################################################################
# Docker context
prompt_docker_context() {
local ctx=${DOCKER_CONTEXT:-default}
if [[ -z ${DOCKER_CONTEXT:-} ]]; then
if (( $+commands[jq] )); then
local cfg=${DOCKER_CONFIG:-~/.docker/config.json}
ctx="$(jq -e -r '.currentContext' $cfg 2>/dev/null)" || ctx=default
else;
ctx=$(docker context show)
fi
fi
[[ -z $ctx || $ctx == default && $_POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT == 0 ]] && return
_p9k_prompt_segment "$0" "$_p9k_color1" "deepskyblue1" 'DOCKER_ICON' 0 '' "$ctx"
}
_p9k_prompt_docker_context_init() {
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[docker]'
}
################################################################
# Docker machine
prompt_docker_machine() {
@ -7495,6 +7516,7 @@ _p9k_init_params() {
_p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES --
_p9k_declare -a POWERLEVEL9K_AWS_CLASSES --
_p9k_declare -a POWERLEVEL9K_AZURE_CLASSES --
_p9k_declare -b POWERLEVEL9K_DOCKER_CONTEXT_SHOW_DEFAULT 0
_p9k_declare -a POWERLEVEL9K_TERRAFORM_CLASSES --
_p9k_declare -b POWERLEVEL9K_TERRAFORM_SHOW_DEFAULT 0
_p9k_declare -a POWERLEVEL9K_GOOGLE_APP_CRED_CLASSES -- 'service_account:*' SERVICE_ACCOUNT