Spaceship-prompt: Error in spaceship_kubecontext

Created on 26 Sep 2017  路  9Comments  路  Source: denysdovhan/spaceship-prompt

Issue

Opening a new shell or tab gives the following output: awk: can't open file /Users/chad.greenburg/.kube/config. I don't have anything related to kubecontext installed or whatever that refers to. Probably need to handle this error gracefully if the file doesn't exist.

Screenshot

screen shot 2017-09-26 at 4 33 22 pm

Environment

Operating system: macOS
Terminal emulator: iTerm
ZSH version: 5.4.2

bug has-pr

Most helpful comment

Another solution if anyone is already editing their prompt order.

The snowflake and error leave after removing kubecontext from SPACESHIP_PROMPT_ORDER. The following is the readme's example order with kubecontext commented out. Add after the theme's source line in .zshrc

# ORDER
SPACESHIP_PROMPT_ORDER=(
  time
  user
  host
  dir
  git
  hg
  package
  node
  ruby
  elixir
  xcode
  swift
  golang
  php
  rust
  julia
  docker
  aws
  venv
  conda
  pyenv
  dotnet
  ember
  # kubecontext
  battery
  exec_time
  line_sep
  vi_mode
  jobs
  exit_code
  char
)

All 9 comments

I solved this problem by creating .kube/config folders.

I think it should look more like this:

# KUBECONTEXT
# Show current context in kubectl.
spaceship_kubecontext() {
  [[ $SPACESHIP_KUBECONTEXT_SHOW == false ]] && return

  # Show KUBECONTEXT status only for folders with .kube and file config inside.
  [[ -f .kube/config ]] || return

  local kube_context=$(awk -F' *: *' '$1 == "current-context" {print $2}' ~/.kube/config)

  _prompt_section \
    "$SPACESHIP_KUBECONTEXT_COLOR" \
    "$SPACESHIP_KUBECONTEXT_PREFIX" \
    "${SPACESHIP_KUBECONTEXT_SYMBOL}${kube_context}" \
    "$SPACESHIP_KUBECONTEXT_SUFFIX"
}

Only problem with @Trioblack's solutions is that now the command line always has a Snowflake emoji.

Minor, but still an annoyance.

the same on Ubuntu into Windows 10

The irritation grew unbearable for me, so I worked around it this way:

Add the following to your ~/.oh-my-zsh/custom/themes/spaceship.zsh-theme:

SPACESHIP_KUBECONTEXT_SHOW="${SPACESHIP_KUBECONTEXT_SHOW:=false}"

Then, reload shell.

Disabling kubecontext section (as @tohuw suggested) might be a solution until PR with a fix will be ready. However, better to add this custom configuration to .zshrc, instead of spaceship.zsh-theme.

Another solution if anyone is already editing their prompt order.

The snowflake and error leave after removing kubecontext from SPACESHIP_PROMPT_ORDER. The following is the readme's example order with kubecontext commented out. Add after the theme's source line in .zshrc

# ORDER
SPACESHIP_PROMPT_ORDER=(
  time
  user
  host
  dir
  git
  hg
  package
  node
  ruby
  elixir
  xcode
  swift
  golang
  php
  rust
  julia
  docker
  aws
  venv
  conda
  pyenv
  dotnet
  ember
  # kubecontext
  battery
  exec_time
  line_sep
  vi_mode
  jobs
  exit_code
  char
)

Best approach is memoryruins answer. If you have no interest in using kubernetes and/or don't have it installed, then this is the quick and easy solution until a patch is pulled into master.

Fixed. Please update to v2.10.2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gillesdemey picture gillesdemey  路  3Comments

Vvkmnn picture Vvkmnn  路  3Comments

janjur picture janjur  路  3Comments

tbekaert picture tbekaert  路  3Comments

salmanulfarzy picture salmanulfarzy  路  3Comments