diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 5daf34f..deeecd2 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -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. diff --git a/config/p10k-lean-8colors.zsh b/config/p10k-lean-8colors.zsh index e0e6cc7..3f23154 100644 --- a/config/p10k-lean-8colors.zsh +++ b/config/p10k-lean-8colors.zsh @@ -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. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index af802d1..73b6782 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -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. diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index 0c90ff9..2a5b991 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -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. diff --git a/internal/icons.zsh b/internal/icons.zsh index 60de344..b6b4630 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -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 diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 90191b9..a3a971f 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -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