add P9K_AWS_PROFILE and P9K_AWS_REGION and use it in default configs

pull/1424/head
Roman Perepelitsa 4 years ago
parent 10918387b3
commit c7ad00b5a5

@ -1291,12 +1291,6 @@
# Tip: Remove the next line to always show aws. # Tip: Remove the next line to always show aws.
typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt' typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt'
# Include AWS region in prompt. (default: false)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION=false
# Shorten AWS region. (default: true)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION_SHORT=true
# POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element # 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. # 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) # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below)
@ -1327,6 +1321,12 @@
typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208 typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208
# typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐'
# AWS segment format. The following parameters are available within the expansion.
#
# - P9K_AWS_PROFILE The name of the current AWS profile.
# - P9K_AWS_REGION The region associated with the current AWS profile.
typeset -g POWERLEVEL9K_AWS_CONTENT_EXPANSION='${P9K_AWS_PROFILE//\%/%%}${P9K_AWS_REGION:+ ${P9K_AWS_REGION//\%/%%}}'
#[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]#
# AWS Elastic Beanstalk environment color. # AWS Elastic Beanstalk environment color.
typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=70 typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=70

@ -1272,12 +1272,6 @@
# Tip: Remove the next line to always show aws. # Tip: Remove the next line to always show aws.
typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt' typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt'
# Include AWS region in prompt. (default: false)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION=false
# Shorten AWS region. (default: true)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION_SHORT=true
# POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element # 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. # 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) # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below)
@ -1308,6 +1302,12 @@
typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=3 typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=3
# typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐'
# AWS segment format. The following parameters are available within the expansion.
#
# - P9K_AWS_PROFILE The name of the current AWS profile.
# - P9K_AWS_REGION The region associated with the current AWS profile.
typeset -g POWERLEVEL9K_AWS_CONTENT_EXPANSION='${P9K_AWS_PROFILE//\%/%%}${P9K_AWS_REGION:+ ${P9K_AWS_REGION//\%/%%}}'
#[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]#
# AWS Elastic Beanstalk environment color. # AWS Elastic Beanstalk environment color.
typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=2 typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=2

@ -1268,12 +1268,6 @@
# Tip: Remove the next line to always show aws. # Tip: Remove the next line to always show aws.
typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt' typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt'
# Include AWS region in prompt. (default: false)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION=false
# Shorten AWS region. (default: true)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION_SHORT=true
# POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element # 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. # 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) # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below)
@ -1304,6 +1298,12 @@
typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208 typeset -g POWERLEVEL9K_AWS_DEFAULT_FOREGROUND=208
# typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐'
# AWS segment format. The following parameters are available within the expansion.
#
# - P9K_AWS_PROFILE The name of the current AWS profile.
# - P9K_AWS_REGION The region associated with the current AWS profile.
typeset -g POWERLEVEL9K_AWS_CONTENT_EXPANSION='${P9K_AWS_PROFILE//\%/%%}${P9K_AWS_REGION:+ ${P9K_AWS_REGION//\%/%%}}'
#[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]#
# AWS Elastic Beanstalk environment color. # AWS Elastic Beanstalk environment color.
typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=70 typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=70

@ -1360,12 +1360,6 @@
# Tip: Remove the next line to always show aws. # Tip: Remove the next line to always show aws.
typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt' typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|awless|terraform|pulumi|terragrunt'
# Include AWS region in prompt. (default: false)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION=false
# Shorten AWS region. (default: true)
# typeset -g POWERLEVEL9K_AWS_SHOW_REGION_SHORT=true
# POWERLEVEL9K_AWS_CLASSES is an array with even number of elements. The first element # 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. # 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) # More specifically, it's P9K_CONTENT prior to the application of context expansion (see below)
@ -1397,6 +1391,12 @@
typeset -g POWERLEVEL9K_AWS_DEFAULT_BACKGROUND=1 typeset -g POWERLEVEL9K_AWS_DEFAULT_BACKGROUND=1
# typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_AWS_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐'
# AWS segment format. The following parameters are available within the expansion.
#
# - P9K_AWS_PROFILE The name of the current AWS profile.
# - P9K_AWS_REGION The region associated with the current AWS profile.
typeset -g POWERLEVEL9K_AWS_CONTENT_EXPANSION='${P9K_AWS_PROFILE//\%/%%}${P9K_AWS_REGION:+ ${P9K_AWS_REGION//\%/%%}}'
#[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]# #[ aws_eb_env: aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) ]#
# AWS Elastic Beanstalk environment color. # AWS Elastic Beanstalk environment color.
typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=2 typeset -g POWERLEVEL9K_AWS_EB_ENV_FOREGROUND=2

@ -1127,37 +1127,62 @@ _p9k_prompt_anaconda_init() {
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${CONDA_PREFIX:-$CONDA_ENV_PATH}' typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${CONDA_PREFIX:-$CONDA_ENV_PATH}'
} }
################################################################ # Populates array `reply` with "$#profile:$profile:$region" where $profile and $region
# AWS Profile # come from the AWS config (~/.aws/config).
prompt_aws() { function _p9k_parse_aws_config() {
local aws_profile="${AWS_VAULT:-${AWSUME_PROFILE:-${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}}}" local cfg=$1
local text="${aws_profile//\%/%%}" typeset -ga reply=()
if (( _POWERLEVEL9K_AWS_SHOW_REGION )); then [[ -f $cfg && -r $cfg ]] || return
local region_full
if [[ -v $AWS_DEFAULT_REGION ]]; then local -a lines
region_full=$AWS_DEFAULT_REGION lines=(${(f)"$(<$cfg)"}) || return
else
if ! _p9k_cache_get "$0-$aws_profile-full"; then local line profile
_p9k_cache_set $(aws configure get region) local -a match mbegin mend
for line in $lines; do
if [[ $line == [[:space:]]#'[default]'[[:space:]]#(|'#'*) ]]; then
# example: [default]
profile=default
elif [[ $line == (#b)'[profile'[[:space:]]##([^[:space:]]|[^[:space:]]*[^[:space:]])[[:space:]]#']'[[:space:]]#(|'#'*) ]]; then
# example: [profile prod]
profile=${(Q)match[1]}
elif [[ $line == (#b)[[:space:]]#region[[:space:]]#=[[:space:]]#([^[:space:]]|[^[:space:]]*[^[:space:]])[[:space:]]# ]]; then
# example: region = eu-west-1
if [[ -n $profile ]]; then
reply+=$#profile:$profile:$match[1]
profile=
fi fi
region_full=$_p9k__cache_val[1]
fi fi
if (( _POWERLEVEL9K_AWS_SHOW_REGION_SHORT )); then done
local region_short=${${${${${${region_full//-}//north/n}//south/s}//east/e}//west/w}//gov/g} }
text="$text ($region_short)"
else
text="$text ($region_full)"
fi
fi
################################################################
# AWS Profile
prompt_aws() {
typeset -g P9K_AWS_PROFILE="${AWS_VAULT:-${AWSUME_PROFILE:-${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}}}"
local pat class local pat class
for pat class in "${_POWERLEVEL9K_AWS_CLASSES[@]}"; do for pat class in "${_POWERLEVEL9K_AWS_CLASSES[@]}"; do
if [[ $aws_profile == ${~pat} ]]; then if [[ $P9K_AWS_PROFILE == ${~pat} ]]; then
[[ -n $class ]] && state=_${${(U)class}//İ/I} [[ -n $class ]] && state=_${${(U)class}//İ/I}
break break
fi fi
done done
_p9k_prompt_segment "$0$state" red white 'AWS_ICON' 0 '' "$text"
if [[ -n $AWS_DEFAULT_REGION ]]; then
typeset -g P9K_AWS_REGION=$AWS_DEFAULT_REGION
else
local cfg=${AWS_CONFIG_FILE:-~/.aws/config}
if ! _p9k_cache_stat_get $0 $cfg; then
local -a reply
_p9k_parse_aws_config $cfg
_p9k_cache_stat_set $reply
fi
local prefix=$#P9K_AWS_PROFILE:$P9K_AWS_PROFILE:
local kv=$_p9k__cache_val[(r)${(b)prefix}*]
typeset -g P9K_AWS_REGION=${kv#$prefix}
fi
_p9k_prompt_segment "$0$state" red white 'AWS_ICON' 0 '' "${P9K_AWS_PROFILE//\%/%%}"
} }
_p9k_prompt_aws_init() { _p9k_prompt_aws_init() {
@ -7398,8 +7423,6 @@ _p9k_init_params() {
# POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow # POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow
_p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES -- _p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES --
_p9k_declare -a POWERLEVEL9K_AWS_CLASSES -- _p9k_declare -a POWERLEVEL9K_AWS_CLASSES --
_p9k_declare -b POWERLEVEL9K_AWS_SHOW_REGION 0
_p9k_declare -b POWERLEVEL9K_AWS_SHOW_REGION_SHORT 1
_p9k_declare -a POWERLEVEL9K_AZURE_CLASSES -- _p9k_declare -a POWERLEVEL9K_AZURE_CLASSES --
_p9k_declare -a POWERLEVEL9K_TERRAFORM_CLASSES -- _p9k_declare -a POWERLEVEL9K_TERRAFORM_CLASSES --
_p9k_declare -b POWERLEVEL9K_TERRAFORM_SHOW_DEFAULT 0 _p9k_declare -b POWERLEVEL9K_TERRAFORM_SHOW_DEFAULT 0

Loading…
Cancel
Save