Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Add kubecontext section to show currently active kubectl context #76

Merged
merged 1 commit into from
Oct 2, 2018

Conversation

owais
Copy link
Contributor

@owais owais commented Oct 1, 2018

Issue: #73

Add kubecontext section

Description

Shows currently active kubectl context

Screenshots (if appropriate):

image

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux

Checklist:

  • I have checked that no other PR duplicates mine
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

Copy link
Owner

@matchai matchai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey owais!

Thank you for your contribution! 😄
A few small comments here and there, but otherwise your PR looks good! 👍

Cheers!

# ------------------------------------------------------------------------------
function __sf_section_kubecontext -d "Display the kubernetes context"
__sf_util_set_default SPACEFISH_KUBECONTEXT_SHOW true
__sf_util_set_default SPACEFISH_KUBECONTEXT_PREFIX " "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the spaceship implementation, the default prefix is "at ": https://github.com/denysdovhan/spaceship-prompt/blob/master/sections/kubecontext.zsh#L13

__sf_util_set_default SPACEFISH_KUBECONTEXT_SHOW true
__sf_util_set_default SPACEFISH_KUBECONTEXT_PREFIX " "
__sf_util_set_default SPACEFISH_KUBECONTEXT_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX
__sf_util_set_default SPACEFISH_KUBECONTEXT_SYMBOL "☸️"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also appears the original implementation has a space following the ☸️ emoji. I would suggest adding it 😃

docs/Options.md Outdated
| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACEFISH_KUBECONTEXT_SHOW` | `true` | Show current kubectl context |
| `SPACEFISH_KUBECONTEXT_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the kubectl section |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest also changing the prefix here to at.

docs/Options.md Outdated
@@ -207,11 +207,24 @@ Go section is shown only in directories that contain `Godeps`, `glide.yaml`, any
| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACEFISH_GOLANG_SHOW` | `true` | Show current Go version or not |
| `SPACEFISH_GOLANG_PREFIX` | `$SPACEFISH_PROMPT_DEFAULT_PREFIX` | Prefix before the Go section |
| `SPACEFISH_GOLANG_PREFIX` | ` ` | Prefix before the Go section |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might've unintentionally changed the value here.
The Go prompt prefix is correct to be $SPACEFISH_PROMPT_DEFAULT_PREFIX.

return
end

set -l sf_kube_context (kubectl config current-context 2>/dev/null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To redirect to stderr in Fish, you would replace 2> with ^ 😄

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this variable is local, I wouldn't use the sf_ prefix. That has only been used in the past for global variables so that we don't occupy the namespace.

__sf_lib_section \
$SPACEFISH_KUBECONTEXT_COLOR \
$SPACEFISH_KUBECONTEXT_PREFIX \
"$SPACEFISH_KUBECONTEXT_SYMBOL $sf_kube_context" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to add the space directly to the symbol (mentioned in the above comment), I would suggest then removing the space here.

docs/README.md Outdated
@@ -17,6 +17,7 @@
* [Haskell (haskell)](./docs/Options.md#haskell-haskell)
* [Pyenv (pyenv)](./docs/Options.md#pyenv-pyenv)
* [Go (golang)](./docs/Options.md#go-golang)
* [Kubectl (kubectl)](./docs/Options.md#kubectl)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in the docs of spaceship, I would change the text here to Kubectl context (kubecontext). You will need to then change the anchor to #kubectl-context-kubecontext. 🔗

docs/Options.md Outdated
| `SPACEFISH_GOLANG_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the Go section |
| `SPACEFISH_GOLANG_SYMBOL` | `🐹·` | Character to be shown before Go version |
| `SPACEFISH_GOLANG_COLOR` | `cyan` | Color of Go section |


### Kubectl \(`kubectl`\)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in the docs of spaceship, I would change the text here to Kubectl context (kubecontext) 😄

@owais
Copy link
Contributor Author

owais commented Oct 2, 2018

@matchai ^

docs/README.md Outdated
@@ -17,6 +17,7 @@
* [Haskell (haskell)](./docs/Options.md#haskell-haskell)
* [Pyenv (pyenv)](./docs/Options.md#pyenv-pyenv)
* [Go (golang)](./docs/Options.md#go-golang)
* [Kubectl (kubectl)](./docs/Options.md#kubectl-context-kubecontext)
Copy link
Owner

@matchai matchai Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nitpick:
I would change the text of the link to Kubectl context \(kubecontext\) 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@matchai
Copy link
Owner

matchai commented Oct 2, 2018

Looks good! Thanks again for your contribution! 😄

@matchai matchai merged commit 8108b6b into matchai:master Oct 2, 2018
@MindTooth
Copy link

This broke with the latest Docker update I believe. Now that Docker bundles kubectl, I have the snow flake all the time.

@matchai
Copy link
Owner

matchai commented Nov 23, 2018

Hmm... It seems you may be right 🤔
@MindTooth Would you mind creating an issue for this? I'll try to address it in the next few days if no one else can.

@MindTooth
Copy link

Done. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants