Skip to content

Commit

Permalink
Merge pull request #40 from jonmosco/symbol_quotes
Browse files Browse the repository at this point in the history
Change quoting for default symbol.  zsh -c reports parsing errors for ansi c style quoting.
  • Loading branch information
jonmosco authored Feb 25, 2018
2 parents fe5484d + 7dd63e3 commit 368012e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Inspired by several tools used to simplify usage of `kubectl`.

## Installing

1. Clone this repository
2. Source the kube-ps1.sh in your `~/.zshrc` or your `~/.bashrc`

This project is now available in brew ports!

```
$ brew update
$ brew install kube-ps1
```

1. Clone this repository
2. Source the kube-ps1.sh in your `~/.zshrc` or your `~/.bashrc`

For Zsh:
```sh
source /path/to/kube-ps1.sh
Expand Down
44 changes: 18 additions & 26 deletions kube-ps1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Override these values in ~/.zshrc or ~/.bashrc
KUBE_PS1_BINARY="${KUBE_PS1_BINARY:-kubectl}"
KUBE_PS1_SYMBOL_ENABLE="${KUBE_PS1_SYMBOL_ENABLE:-true}"
KUBE_PS1_SYMBOL_DEFAULT=${KUBE_PS1_SYMBOL_DEFAULT:-$'\u2388 '}
KUBE_PS1_SYMBOL_DEFAULT="${KUBE_PS1_SYMBOL_DEFAULT:-\u2388 }"
KUBE_PS1_SYMBOL_USE_IMG="${KUBE_PS1_SYMBOL_USE_IMG:-false}"
KUBE_PS1_NS_ENABLE="${KUBE_PS1_NS_ENABLE:-true}"
KUBE_PS1_PREFIX="${KUBE_PS1_PREFIX-(}"
Expand Down Expand Up @@ -179,33 +179,25 @@ _kube_ps1_binary_check() {
_kube_ps1_symbol() {
[[ "${KUBE_PS1_SYMBOL_ENABLE}" == false ]] && return

local _KUBE_PS1_SYMBOL_IMG
local _KUBE_PS1_SYMBOL_DEFAULT

# TODO: Test terminal capabilities
# If LANG is set to POSIX, the hex will
# work.
# [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]
# Bash only supports \u \U since 4.2
if [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then
if ((BASH_VERSINFO[0] >= 4)) && [[ $'\u2388 ' != "\\u2388 " ]]; then
_KUBE_PS1_SYMBOL_DEFAULT="${KUBE_PS1_SYMBOL_DEFAULT}"
_KUBE_PS1_SYMBOL_IMG=$'\u2638 '
else
_KUBE_PS1_SYMBOL_DEFAULT=$'\xE2\x8E\x88 '
_KUBE_PS1_SYMBOL_IMG=$'\xE2\x98\xB8 '
fi
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
_KUBE_PS1_SYMBOL_DEFAULT="${KUBE_PS1_SYMBOL_DEFAULT}"
_KUBE_PS1_SYMBOL_IMG=$'\u2638 '
else
_KUBE_PS1_SYMBOL_DEFAULT="k8s"
fi
case "${KUBE_PS1_SHELL}" in
bash)
if ((BASH_VERSINFO[0] >= 4)) && [[ $'\u2388 ' != "\\u2388 " ]]; then
KUBE_PS1_SYMBOL=$'\u2388 '
KUBE_PS1_SYMBOL_IMG=$'\u2638 '
else
KUBE_PS1_SYMBOL=$'\xE2\x8E\x88 '
KUBE_PS1_SYMBOL_IMG=$'\xE2\x98\xB8 '
fi
;;
zsh)
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_DEFAULT}"
KUBE_PS1_SYMBOL_IMG="\u2638 ";;
*)
KUBE_PS1_SYMBOL="k8s"
esac

if [[ "${KUBE_PS1_SYMBOL_USE_IMG}" == true ]]; then
KUBE_PS1_SYMBOL="${_KUBE_PS1_SYMBOL_IMG}"
else
KUBE_PS1_SYMBOL="${_KUBE_PS1_SYMBOL_DEFAULT}"
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_IMG}"
fi

echo "${KUBE_PS1_SYMBOL}"
Expand Down

0 comments on commit 368012e

Please sign in to comment.