This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubecontext section to show currently active kubectl context (#76)
Closes #73
- Loading branch information
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Kubernetes (kubectl) | ||
# | ||
# Kubernetes is an open-source system for deployment, scaling, | ||
# and management of containerized applications. | ||
# Link: https://kubernetes.io/ | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Configuration | ||
# ------------------------------------------------------------------------------ | ||
function __sf_section_kubecontext -d "Display the kubernetes context" | ||
__sf_util_set_default SPACEFISH_KUBECONTEXT_SHOW true | ||
__sf_util_set_default SPACEFISH_KUBECONTEXT_PREFIX "at " | ||
__sf_util_set_default SPACEFISH_KUBECONTEXT_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX | ||
__sf_util_set_default SPACEFISH_KUBECONTEXT_SYMBOL "鈽革笍 " | ||
__sf_util_set_default SPACEFISH_KUBECONTEXT_COLOR cyan | ||
|
||
[ $SPACEFISH_KUBECONTEXT_SHOW = false ]; and return | ||
|
||
if not type -q kubectl | ||
return | ||
end | ||
|
||
set -l sf_kube_context (kubectl config current-context ^/dev/null) | ||
|
||
__sf_lib_section \ | ||
$SPACEFISH_KUBECONTEXT_COLOR \ | ||
$SPACEFISH_KUBECONTEXT_PREFIX \ | ||
"$SPACEFISH_KUBECONTEXT_SYMBOL$sf_kube_context" \ | ||
$SPACEFISH_KUBECONTEXT_SUFFIX | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
source $DIRNAME/spacefish_test_setup.fish | ||
source $DIRNAME/mock.fish | ||
|
||
function setup | ||
spacefish_test_setup | ||
mock kubectl 0 "echo \"testkube\"" | ||
end | ||
|
||
test "Prints section " | ||
( | ||
set_color --bold fff | ||
echo -n "at " | ||
set_color normal | ||
set_color --bold cyan | ||
echo -n "鈽革笍 testkube" | ||
set_color normal | ||
set_color --bold fff | ||
echo -n " " | ||
set_color normal | ||
) = (__sf_section_kubecontext) | ||
end | ||
|
||
test "Changing SPACEFISH_KUBECONTEXT_SYMBOL changes the displayed character" | ||
( | ||
set SPACEFISH_KUBECONTEXT_SYMBOL "路 " | ||
|
||
set_color --bold fff | ||
echo -n "at " | ||
set_color normal | ||
set_color --bold cyan | ||
echo -n "路 testkube" | ||
set_color normal | ||
set_color --bold fff | ||
echo -n " " | ||
set_color normal | ||
) = (__sf_section_kubecontext) | ||
end | ||
|
||
test "Changing SPACEFISH_KUBECONTEXT_PREFIX changes the character prefix" | ||
( | ||
set sf_exit_code 0 | ||
set SPACEFISH_KUBECONTEXT_PREFIX 路 | ||
|
||
set_color --bold fff | ||
echo -n "路" | ||
set_color normal | ||
set_color --bold cyan | ||
echo -n "鈽革笍 testkube" | ||
set_color normal | ||
set_color --bold fff | ||
echo -n " " | ||
set_color normal | ||
) = (__sf_section_kubecontext) | ||
end | ||
|
||
test "Changing SPACEFISH_KUBECONTEXT_SUFFIX changes the character prefix" | ||
( | ||
set sf_exit_code 0 | ||
set SPACEFISH_KUBECONTEXT_SUFFIX 路 | ||
|
||
set_color --bold fff | ||
echo -n "at " | ||
set_color normal | ||
set_color --bold cyan | ||
echo -n "鈽革笍 testkube" | ||
set_color normal | ||
set_color --bold fff | ||
echo -n "路" | ||
set_color normal | ||
) = (__sf_section_kubecontext) | ||
end | ||
|
||
test "Doesn't display node when SPACEFISH_KUBECONTEXT_SHOW is set to 'false'" | ||
( | ||
set SPACEFISH_KUBECONTEXT_SHOW false | ||
) = (__sf_section_kubecontext) | ||
end | ||
|