From 4ef1a9bbdd21a2935eb94780b2cb43c6bc042b9e Mon Sep 17 00:00:00 2001 From: romkatv Date: Tue, 8 Oct 2019 13:46:39 +0200 Subject: [PATCH] add azure prompt segment --- config/p10k-classic.zsh | 7 +++++++ config/p10k-lean.zsh | 7 +++++++ internal/icons.zsh | 5 +++++ internal/p10k.zsh | 15 +++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 1c910039..54d90755 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -59,6 +59,7 @@ kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) + # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) context # user@hostname nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) @@ -658,6 +659,12 @@ # Custom icon. # typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ azure: azure account name (https://docs.microsoft.com/en-us/cli/azure) ]########## + # Azure account name color. + typeset -g POWERLEVEL9K_AZURE_FOREGROUND=32 + # Custom icon. + # typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION='⭐' + #############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]############# # Kubernetes context classes for the purpose of using different colors, icons and expansions with # different contexts. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 7d3d6cba..68c34dbd 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -59,6 +59,7 @@ kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) + # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) context # user@hostname nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) @@ -718,6 +719,12 @@ # Custom icon. # typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ azure: azure account name (https://docs.microsoft.com/en-us/cli/azure) ]########## + # Azure account name color. + typeset -g POWERLEVEL9K_AZURE_FOREGROUND=32 + # Custom icon. + # typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION='⭐' + ###############################[ public_ip: public IP address ]############################### # Public IP color. typeset -g POWERLEVEL9K_PUBLIC_IP_FOREGROUND=94 diff --git a/internal/icons.zsh b/internal/icons.zsh index 718e1663..b93bbb53 100755 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -114,6 +114,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\U1F6E0\u00A0' # 🛠️ PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + AZURE_ICON '\u2601' # ☁ ) ;; 'awesome-fontconfig') @@ -215,6 +216,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\U1F6E0\u00A0' # 🛠️ PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + AZURE_ICON '\u2601' # ☁ ) ;; 'awesome-mapped-fontconfig') @@ -320,6 +322,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\U1F6E0\u00A0' # 🛠️ PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + AZURE_ICON '\u2601' # ☁ ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -422,6 +425,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\U1F6E0\u00A0' # 🛠️ PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '\uE77F' #  + AZURE_ICON '\uFD03' # ﴃ ) ;; *) @@ -523,6 +527,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\U1F6E0\u00A0' # 🛠️ PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + AZURE_ICON '\u2601' # ☁ ) ;; esac diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 7993fe7a..24239e27 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3035,6 +3035,21 @@ prompt_java_version() { _p9k_prompt_segment "$0" "red" "white" "JAVA_ICON" 0 '' "${v//\%/%%}" } +prompt_azure() { + (( $+commands[az] )) || return + local cfg=${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json + local -H stat + zstat -H stat -- $cfg 2>/dev/null || return + local sig="$stat[inode].$stat[mtime].$stat[size].$stat[mode]" + if ! _p9k_cache_get $0 || [[ $_p9k_cache_val[1] != $sig ]]; then + local name + name="$(az account show --query name --output tsv 2>/dev/null)" || name= + _p9k_cache_set "$sig" "$name" + fi + [[ -n $_p9k_cache_val[2] ]] || return + _p9k_prompt_segment "$0" "blue" "white" "AZURE_ICON" 0 '' "${_p9k_cache_val[2]//\%/%%}" +} + typeset -gra __p9k_nordvpn_tag=( P9K_NORDVPN_STATUS P9K_NORDVPN_TECHNOLOGY