Skip to content

Commit

Permalink
Add optional vars before and after the prompt (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithPeder authored and superbrothers committed Jun 3, 2019
1 parent c97dac5 commit 7bce5fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ Change the separator between context and namespace:
zstyle ':zsh-kubectl-prompt:' separator '|'
```

Add custom character before the prompt:

```sh
zstyle ':zsh-kubectl-prompt:' preprompt '<'
```

Add custom character after the prompt:

```sh
zstyle ':zsh-kubectl-prompt:' postprompt '>'
```

Does not display the current namespace:

```sh
Expand Down
11 changes: 9 additions & 2 deletions kubectl.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function _zsh_kubectl_prompt_precmd() {
fi
zstyle ':zsh-kubectl-prompt:' updated_at "$now"

# Set environment variable if context is not set
if ! context="$(kubectl config current-context 2>/dev/null)"; then
ZSH_KUBECTL_PROMPT="current-context is not set"
return 1
Expand All @@ -62,14 +63,20 @@ function _zsh_kubectl_prompt_precmd() {
[[ -z "$ns" ]] && ns="default"
ZSH_KUBECTL_NAMESPACE="${ns}"

# Specify the entry before prompt (default empty)
zstyle -s ':zsh-kubectl-prompt:' preprompt preprompt
# Specify the entry after prompt (default empty)
zstyle -s ':zsh-kubectl-prompt:' postprompt postprompt

# Set environment variable without namespace
zstyle -s ':zsh-kubectl-prompt:' namespace namespace
if [[ "$namespace" != true ]]; then
ZSH_KUBECTL_PROMPT="${context}"
ZSH_KUBECTL_PROMPT="${preprompt}${context}${postprompt}"
return 0
fi

zstyle -s ':zsh-kubectl-prompt:' separator separator
ZSH_KUBECTL_PROMPT="${context}${separator}${ns}"
ZSH_KUBECTL_PROMPT="${preprompt}${context}${separator}${ns}${postprompt}"

return 0
}

0 comments on commit 7bce5fd

Please sign in to comment.