From 1e009cf43aada792c72414e244e116e932462bc5 Mon Sep 17 00:00:00 2001 From: Rostyslav Sotnychenko Date: Thu, 14 Nov 2019 13:40:28 +0200 Subject: [PATCH] Add support for classes for AWS profile prompt --- config/p10k-classic.zsh | 32 +++++++++++++++++++++++++++++--- config/p10k-lean.zsh | 32 +++++++++++++++++++++++++++++--- config/p10k-rainbow.zsh | 34 ++++++++++++++++++++++++++++++---- internal/p10k.zsh | 17 +++++++++++++---- 4 files changed, 101 insertions(+), 14 deletions(-) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 70ae4cf..9fa60c4 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -678,9 +678,35 @@ #[ aws: aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) ]# # AWS profile color. - typeset -g POWERLEVEL9K_AWS_FOREGROUND=208 - # Custom icon. - # typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='⭐' + typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208 + # POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element + # in each pair defines a pattern against which the current AWS profile gets matched. + # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below) + # that gets matched. If you unset all POWERLEVEL9K_AWS_*CONTENT_EXPANSION parameters, + # you'll see this value in your prompt. The second element of each pair in + # POWERLEVEL9K_AWS_CLASSES defines the context class. Patterns are tried in order. The + # first match wins. + # + # For example, given these settings: + # + # typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD + # '*test*' TEST + # '*' DEFAULT) + # + # If your current AWS profile is "company_test", its class is TEST + # because "company_test" doesn't match the pattern '*prod*' but does match '*test*'. + # + # You can define different colors, icons and content expansions for different classes: + # + # typeset -g POWERLEVEL9K_AWS_TEST_FOREGROUND=28 + # typeset -g POWERLEVEL9K_AWS_TEST_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_AWS_TEST_CONTENT_EXPANSION='> ${P9K_CONTENT} <' + typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD # These values are examples that are unlikely + # '*test*' TEST # to match your needs. Customize them as needed. + '*' DEFAULT) + # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# # AWS Elastic Beanstalk environment color. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 42d7938..9f14440 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -735,9 +735,35 @@ #[ aws: aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) ]# # AWS profile color. - typeset -g POWERLEVEL9K_AWS_FOREGROUND=208 - # Custom icon. - # typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='⭐' + typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208 + # POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element + # in each pair defines a pattern against which the current AWS profile gets matched. + # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below) + # that gets matched. If you unset all POWERLEVEL9K_AWS_*CONTENT_EXPANSION parameters, + # you'll see this value in your prompt. The second element of each pair in + # POWERLEVEL9K_AWS_CLASSES defines the context class. Patterns are tried in order. The + # first match wins. + # + # For example, given these settings: + # + # typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD + # '*test*' TEST + # '*' DEFAULT) + # + # If your current AWS profile is "company_test", its class is TEST + # because "company_test" doesn't match the pattern '*prod*' but does match '*test*'. + # + # You can define different colors, icons and content expansions for different classes: + # + # typeset -g POWERLEVEL9K_AWS_TEST_FOREGROUND=28 + # typeset -g POWERLEVEL9K_AWS_TEST_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_AWS_TEST_CONTENT_EXPANSION='> ${P9K_CONTENT} <' + typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD # These values are examples that are unlikely + # '*test*' TEST # to match your needs. Customize them as needed. + '*' DEFAULT) + # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# # AWS Elastic Beanstalk environment color. diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index fb64dba..2e2e93b 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -694,10 +694,36 @@ #[ aws: aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) ]# # AWS profile color. - # typeset -g POWERLEVEL9K_AWS_FOREGROUND=7 - # typeset -g POWERLEVEL9K_AWS_BACKGROUND=1 - # Custom icon. - # typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=7 + # typeset -g POWERLEVEL9K_AWS_DEFAULT_BACKGROUND=1 + # POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element + # in each pair defines a pattern against which the current AWS profile gets matched. + # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below) + # that gets matched. If you unset all POWERLEVEL9K_AWS_*CONTENT_EXPANSION parameters, + # you'll see this value in your prompt. The second element of each pair in + # POWERLEVEL9K_AWS_CLASSES defines the context class. Patterns are tried in order. The + # first match wins. + # + # For example, given these settings: + # + # typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD + # '*test*' TEST + # '*' DEFAULT) + # + # If your current AWS profile is "company_test", its class is TEST + # because "company_test" doesn't match the pattern '*prod*' but does match '*test*'. + # + # You can define different colors, icons and content expansions for different classes: + # + # typeset -g POWERLEVEL9K_AWS_TEST_FOREGROUND=28 + # typeset -g POWERLEVEL9K_AWS_TEST_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_AWS_TEST_CONTENT_EXPANSION='> ${P9K_CONTENT} <' + typeset -g POWERLEVEL9K_AWS_CLASSES=( + # '*prod*' PROD # These values are examples that are unlikely + # '*test*' TEST # to match your needs. Customize them as needed. + '*' DEFAULT) + # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# # AWS Elastic Beanstalk environment color. diff --git a/internal/p10k.zsh b/internal/p10k.zsh index a2f0fab..ec4a06d 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -978,7 +978,15 @@ prompt_anaconda() { prompt_aws() { local aws_profile="${AWS_VAULT:-${AWSUME_PROFILE:-${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}}}" if [[ -n "$aws_profile" ]]; then - _p9k_prompt_segment "$0" red white 'AWS_ICON' 0 '' "${aws_profile//\%/%%}" + local pat class + for pat class in "${_POWERLEVEL9K_AWS_CLASSES[@]}"; do + if [[ $aws_profile == ${~pat} ]]; then + [[ -n $class ]] && state=_${(U)class} + break + fi + done + + _p9k_prompt_segment "$0$state" red white 'AWS_ICON' 0 '' "${aws_profile//\%/%%}" fi } @@ -1085,7 +1093,7 @@ prompt_battery() { local -a bats=( /sys/class/power_supply/(BAT*|battery)/(FN) ) (( $#bats )) || return - local -i energy_now energy_full power_now + local -i energy_now energy_full power_now local -i is_full=1 is_calculating is_charching local dir for dir in $bats; do @@ -4439,7 +4447,7 @@ _p9k_init_async_pump() { local ip_url=$_POWERLEVEL9K_PUBLIC_IP_HOST local lock=$_p9k__async_pump_lock local fifo=$_p9k__async_pump_fifo - $functions[_p9k_async_pump]" + $functions[_p9k_async_pump]" local setsid=${commands[setsid]:-/usr/local/opt/util-linux/bin/setsid} [[ -f $setsid ]] && setsid=${(q)setsid} || setsid= @@ -4602,7 +4610,7 @@ _p9k_init_vars() { _p9k_init_params() { # invarint: _POWERLEVEL9K_INSTANT_PROMPT == (verbose|quiet|off) - # invariant: [[ ($_POWERLEVEL9K_INSTANT_PROMPT == off) == $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT ]] + # invariant: [[ ($_POWERLEVEL9K_INSTANT_PROMPT == off) == $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT ]] _p9k_declare -s POWERLEVEL9K_INSTANT_PROMPT # verbose, quiet, off if [[ $_POWERLEVEL9K_INSTANT_PROMPT == off ]]; then typeset -gi _POWERLEVEL9K_DISABLE_INSTANT_PROMPT=1 @@ -4852,6 +4860,7 @@ _p9k_init_params() { # POWERLEVEL9K_KUBECONTEXT_TESTING_BACKGROUND=green # POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow _p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES -- + _p9k_declare -a POWERLEVEL9K_AWS_CLASSES -- # Specifies the format of java version. # # POWERLEVEL9K_JAVA_VERSION_FULL=true => 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03