2023-02-07 12:33:59 +01:00
|
|
|
# AZ Get Subscritions
|
|
|
|
function azgs() {
|
|
|
|
az account show --output tsv --query 'name' 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# AZ Subscription Selection
|
|
|
|
alias azss="az account set --subscription"
|
|
|
|
|
|
|
|
|
|
|
|
function az_subscriptions() {
|
|
|
|
az account list --all --output tsv --query '[*].name' 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function _az_subscriptions() {
|
|
|
|
reply=($(az_subscriptions))
|
|
|
|
}
|
|
|
|
compctl -K _az_subscriptions azss
|
|
|
|
|
|
|
|
# Azure prompt
|
|
|
|
function azure_prompt_info() {
|
2023-04-08 11:13:30 +02:00
|
|
|
[[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json" ]] && return
|
2023-02-07 12:33:59 +01:00
|
|
|
# azgs is too expensive, if we have jq, we enable the prompt
|
|
|
|
(( $+commands[jq] )) || return 1
|
2023-04-08 11:13:30 +02:00
|
|
|
azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json")
|
2023-02-07 12:33:59 +01:00
|
|
|
echo "${ZSH_THEME_AZURE_PREFIX:=<az:}${azgs}${ZSH_THEME_AZURE_SUFFIX:=>}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Load az completions
|
|
|
|
function _az-homebrew-installed() {
|
|
|
|
# check if Homebrew is installed
|
|
|
|
(( $+commands[brew] )) || return 1
|
|
|
|
|
|
|
|
# speculatively check default brew prefix
|
2023-02-23 23:00:31 +01:00
|
|
|
if [[ -d /usr/local ]]; then
|
|
|
|
_brew_prefix=/usr/local
|
|
|
|
elif [[ -d /opt/homebrew ]]; then
|
|
|
|
_brew_prefix=/opt/homebrew
|
2023-02-07 12:33:59 +01:00
|
|
|
else
|
|
|
|
# ok, it is not in the default prefix
|
|
|
|
# this call to brew is expensive (about 400 ms), so at least let's make it only once
|
2023-02-23 23:00:31 +01:00
|
|
|
_brew_prefix=$(brew --prefix)
|
2023-02-07 12:33:59 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# get az.completion.sh location from $PATH
|
|
|
|
_az_zsh_completer_path="$commands[az_zsh_completer.sh]"
|
|
|
|
|
|
|
|
# otherwise check common locations
|
|
|
|
if [[ -z $_az_zsh_completer_path ]]; then
|
|
|
|
# Homebrew
|
|
|
|
if _az-homebrew-installed; then
|
2023-02-23 23:00:31 +01:00
|
|
|
_az_zsh_completer_path=$_brew_prefix/etc/bash_completion.d/az
|
2023-02-07 12:33:59 +01:00
|
|
|
# Linux
|
|
|
|
else
|
|
|
|
_az_zsh_completer_path=/etc/bash_completion.d/azure-cli
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-02-23 23:00:31 +01:00
|
|
|
[[ -r $_az_zsh_completer_path ]] && autoload -U +X bashcompinit && bashcompinit && source $_az_zsh_completer_path
|
2023-02-07 12:33:59 +01:00
|
|
|
unset _az_zsh_completer_path _brew_prefix
|