mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2025-12-06 15:30:40 +01:00
feat(azure): add azure plugin (#8848)
Co-authored-by: hagridaaron <hagridaaron@gmail.com> Co-authored-by: Terry <tmoschou@gmail.com> Closes #8847
This commit is contained in:
committed by
GitHub
parent
3fd63fdf01
commit
379fe0fe13
60
plugins/azure/azure.plugin.zsh
Normal file
60
plugins/azure/azure.plugin.zsh
Normal file
@@ -0,0 +1,60 @@
|
||||
# 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() {
|
||||
[[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}" ]] && return
|
||||
# azgs is too expensive, if we have jq, we enable the prompt
|
||||
(( $+commands[jq] )) || return 1
|
||||
azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' ${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json})
|
||||
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
|
||||
if [ -h /usr/local/opt/az ]; then
|
||||
_brew_prefix=/usr/local/opt/az
|
||||
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
|
||||
_brew_prefix=$(brew --prefix azure-cli)
|
||||
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
|
||||
_az_zsh_completer_path=$_brew_prefix/libexec/bin/az.completion.sh
|
||||
# Linux
|
||||
else
|
||||
_az_zsh_completer_path=/etc/bash_completion.d/azure-cli
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ -r $_az_zsh_completer_path ]] && source $_az_zsh_completer_path
|
||||
unset _az_zsh_completer_path _brew_prefix
|
||||
Reference in New Issue
Block a user