Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

[New Segment]: Microsoft Azure Subscription segment (async) #1396

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ The segments that are currently available are:
* [`docker_machine`](segments/docker_machine/README.md) - The current Docker Machine.
* [`kubecontext`](segments/kubecontext/README.md) - The current context of your `kubectl` configuration.
* [`dropbox`](segments/dropbox/README.md) - Indicates Dropbox directory and syncing status using `dropbox-cli`
* [`azure`](segments/azure/README.md) - The current active MS Azure subscription.

**Other:**
* [`custom_*`](segments/custom/README.md) - Create a custom segment to display the
Expand Down
27 changes: 27 additions & 0 deletions segments/azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Azure

![](segment.png)

## Installation

To use this segment, you need to activate it by adding `azure` to your
`P9K_LEFT_PROMPT_ELEMENTS` or `P9K_RIGHT_PROMPT_ELEMENTS` array, depending
where you want to show this segment.

## Configuration

This segment shows the current active Microsoft Azure subscription using the `az`command provided by [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)


### Color Customization

You can change the foreground and background color of this segment by setting
```
P9K_AZURE_FOREGROUND='red'
P9K_AZURE_BACKGROUND='blue'
```

### Customize Icon

The main Icon can be changed by setting `P9K_AZURE_ICON="my_icon"`. To change the
icon color only, set `P9K_AZURE_ICON_COLOR="red"`.
53 changes: 53 additions & 0 deletions segments/azure/azure.p9k
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
################################################################
# @title powerlevel9k Segment - Python Environment
# @source [powerlevel9k](https://github.com/bhilburn/powerlevel9k)
##

(){
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
################################################################
# Register segment
# Parameters:
# segment_name context background foreground Generic Flat/Awesome-Patched Awesome-FontConfig Awesome-Mapped-FontConfig NerdFont
#   ☁ ﴃ
p9k::register_segment "AZURE" "" "69" "231" '' $'\uE60F' $'\uE60F' $'\U2601' $'\uFD03 '

################################################################
}

################################################################
# @description
# Display the current active Microsoft Azure subscription
##
# @args
# $1 string Alignment - left | right
# $2 integer Segment index
# $3 boolean Whether the segment should be joined
##
prompt_azure() {
if [ $commands[az] ]; then
init_az_fetch_script
nohup ~/.az_fetch_sub.sh > /dev/null 2>&1 &

local subscription_name=""
if [[ -f ~/.az_current_sub ]]; then
subscription_name="$(cat ~/.az_current_sub)"
fi

if [[ -n "$subscription_name" ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "${subscription_name}"
fi
fi
}

init_az_fetch_script() {
if [[ ! -f ~/.az_fetch_sub.sh ]]; then
cat <<EOF > ~/.az_fetch_sub.sh
#!/bin/bash
echo "\$(az account show --query name -o tsv)" > ~/.az_current_sub
EOF
chmod +x ~/.az_fetch_sub.sh
fi
}
Binary file added segments/azure/segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
282 changes: 282 additions & 0 deletions segments/azure/segment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.