From a8f9527079e15588af3e98f94f3c6a427664ddce Mon Sep 17 00:00:00 2001 From: romkatv Date: Thu, 5 Dec 2019 23:53:30 +0100 Subject: [PATCH] add gcloud prompt segment; fixes #366 --- config/p10k-classic.zsh | 12 ++++++++++++ config/p10k-lean.zsh | 12 ++++++++++++ config/p10k-rainbow.zsh | 13 +++++++++++++ internal/icons.zsh | 5 +++++ internal/p10k.zsh | 13 +++++++++++++ 5 files changed, 55 insertions(+) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 22cb2c97..4fe11f8a 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -67,6 +67,7 @@ aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) + # gcloud # google cloud acccount and project (https://cloud.google.com/) context # user@hostname nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) @@ -761,6 +762,17 @@ # Custom icon. # typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ gcloud: google cloud acccount and project (https://cloud.google.com/) ]########### + # Google cloud color. + typeset -g POWERLEVEL9K_GCLOUD_FOREGROUND=32 + + # Google cloud format. Uncomment and edit the next line if the default is too verbose. + # Note: ${X//\%/%%} is the same as $X but with all occurences of % replaced with %%. + # typeset -g POWERLEVEL9K_GCLOUD_CONTENT_EXPANSION='${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}' + + # Custom icon. + # typeset -g POWERLEVEL9K_GCLOUD_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 e9d560f8..4a9e5ce1 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -67,6 +67,7 @@ aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) + # gcloud # google cloud acccount and project (https://cloud.google.com/) context # user@hostname nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) @@ -818,6 +819,17 @@ # Custom icon. # typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ gcloud: google cloud acccount and project (https://cloud.google.com/) ]########### + # Google cloud color. + typeset -g POWERLEVEL9K_GCLOUD_FOREGROUND=32 + + # Google cloud format. Uncomment and edit the next line if the default is too verbose. + # Note: ${X//\%/%%} is the same as $X but with all occurences of % replaced with %%. + # typeset -g POWERLEVEL9K_GCLOUD_CONTENT_EXPANSION='${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}' + + # Custom icon. + # typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐' + ###############################[ public_ip: public IP address ]############################### # Public IP color. typeset -g POWERLEVEL9K_PUBLIC_IP_FOREGROUND=94 diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index 151210e8..ffdd4158 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -67,6 +67,7 @@ aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) + # gcloud # google cloud acccount and project (https://cloud.google.com/) context # user@hostname nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) ranger # ranger shell (https://github.com/ranger/ranger) @@ -785,6 +786,18 @@ # Custom icon. # typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ gcloud: google cloud acccount and project (https://cloud.google.com/) ]########### + # Google cloud color. + # typeset -g POWERLEVEL9K_GCLOUD_FOREGROUND=7 + # typeset -g POWERLEVEL9K_GCLOUD_BACKGROUND=4 + + # Google cloud format. Uncomment and edit the next line if the default is too verbose. + # Note: ${X//\%/%%} is the same as $X but with all occurences of % replaced with %%. + # typeset -g POWERLEVEL9K_GCLOUD_CONTENT_EXPANSION='${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}' + + # Custom icon. + # typeset -g POWERLEVEL9K_GCLOUD_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/internal/icons.zsh b/internal/icons.zsh index 23433d56..95d38888 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -119,6 +119,7 @@ function _p9k_init_icons() { AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' + GCLOUD_ICON 'G' ) ;; 'awesome-fontconfig') @@ -225,6 +226,7 @@ function _p9k_init_icons() { AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' + GCLOUD_ICON 'G' ) ;; 'awesome-mapped-fontconfig') @@ -335,6 +337,7 @@ function _p9k_init_icons() { AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' + GCLOUD_ICON 'G' ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -442,6 +445,7 @@ function _p9k_init_icons() { AZURE_ICON '\uFD03' # ﴃ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' + GCLOUD_ICON '\uF7B7' #  ) ;; *) @@ -548,6 +552,7 @@ function _p9k_init_icons() { AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' + GCLOUD_ICON 'G' ) ;; esac diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 56bd9fae..f0f0707e 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3351,6 +3351,19 @@ prompt_azure() { _p9k_prompt_segment "$0" "blue" "white" "AZURE_ICON" 0 '' "${_p9k_cache_val[1]//\%/%%}" } +prompt_gcloud() { + unset P9K_GCLOUD_PROJECT P9K_GCLOUD_ACCOUNT + (( $+commands[gcloud] )) || return + local cfg=${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json + if ! _p9k_cache_stat_get $0 ~/.config/gcloud/active_config ~/.config/gcloud/configurations/config_default; then + _p9k_cache_stat_set "$(gcloud config get-value account 2>/dev/null)" "$(gcloud config get-value project 2>/dev/null)" + fi + [[ -n $_p9k_cache_val[1] || -n $_p9k_cache_val[2] ]] || return + P9K_GCLOUD_ACCOUNT=$_p9k_cache_val[1] + P9K_GCLOUD_PROJECT=$_p9k_cache_val[2] + _p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}" +} + typeset -gra __p9k_nordvpn_tag=( P9K_NORDVPN_STATUS P9K_NORDVPN_TECHNOLOGY