Skip to content

Commit

Permalink
Add support for multiple kubeconfig files (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
superbrothers authored Mar 15, 2019
1 parent 802ad42 commit 46081ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kubectl.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ function() {

add-zsh-hook precmd _zsh_kubectl_prompt_precmd
function _zsh_kubectl_prompt_precmd() {
local kubeconfig updated_at now context namespace ns separator modified_time_fmt
local kubeconfig config updated_at now context namespace ns separator modified_time_fmt

kubeconfig="$HOME/.kube/config"
if [[ -n "$KUBECONFIG" ]]; then
kubeconfig="$KUBECONFIG"
fi

zstyle -s ':zsh-kubectl-prompt:' modified_time_fmt modified_time_fmt
if ! now="$(stat -L $modified_time_fmt "$kubeconfig" 2>/dev/null)"; then
ZSH_KUBECTL_PROMPT="kubeconfig is not found"
return 1
fi

# KUBECONFIG environment variable can hold a list of kubeconfig files that is colon-delimited.
# Therefore, if KUBECONFIG has been held multiple files, each files need to be checked.
while read -d ":" config; do
if ! now="${now}$(stat -L $modified_time_fmt "$config" 2>/dev/null)"; then
ZSH_KUBECTL_PROMPT="$config doesn't exist"
return 1
fi
done <<< "${kubeconfig}:"

zstyle -s ':zsh-kubectl-prompt:' updated_at updated_at
if [[ "$updated_at" == "$now" ]]; then
Expand Down

0 comments on commit 46081ea

Please sign in to comment.