Skip to content

Commit

Permalink
Add docker_context segment
Browse files Browse the repository at this point in the history
Adds docker_context segment to show current docker context, with
SHOW_ON_COMMAND and SHOW_DEFAULT parameters.

Closes romkatv#1485
  • Loading branch information
treuherz committed Nov 17, 2021
1 parent a9f208c commit 4dea8c7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/p10k-classic.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'

This comment has been minimized.

Copy link
@thirdgen88

thirdgen88 Nov 24, 2021

Should we include docker-compose here (even though Compose V2 via docker compose would work fine here) for convenience?

# 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.
Expand Down
8 changes: 8 additions & 0 deletions config/p10k-lean-8colors.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions config/p10k-lean.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions config/p10k-rainbow.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions internal/icons.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' #
DOCKER_ICON '\U1F433' # 🐳
)
;;
'awesome-fontconfig')
Expand Down Expand Up @@ -278,6 +279,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' #
DOCKER_ICON '\U1F433' # 🐳
)
;;
'awesome-mapped-fontconfig')
Expand Down Expand Up @@ -412,6 +414,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' #
DOCKER_ICON '\U1F433' # 🐳
)
;;
'nerdfont-complete'|'nerdfont-fontconfig')
Expand Down Expand Up @@ -544,6 +547,7 @@ function _p9k_init_icons() {
JULIA_ICON '\uE624' #
SCALA_ICON '\uE737' #
TOOLBOX_ICON '\uE20F'$s #
DOCKER_ICON '\U1F433' # 🐳
)
;;
ascii)
Expand Down Expand Up @@ -673,6 +677,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON 'toolbox'
DOCKER_ICON 'docker'
)
;;
*)
Expand Down Expand Up @@ -804,6 +809,7 @@ function _p9k_init_icons() {
JULIA_ICON 'jl'
SCALA_ICON 'scala'
TOOLBOX_ICON '\u2B22' #
DOCKER_ICON '\U1F433' # 🐳
)
;;
esac
Expand Down
22 changes: 22 additions & 0 deletions internal/p10k.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4dea8c7

Please sign in to comment.