Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor k8s support #330

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf.d/pure.fish
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ _pure_set_default pure_symbol_ssh_prefix "" # suggestion: 'ssh:/' or '🔗🔐
# Display Kubernetes/k8s context and namespace
_pure_set_default pure_enable_k8s false
_pure_set_default pure_symbol_k8s_prefix "☸" # ☸️
_pure_set_default pure_color_k8s_prefix pure_color_dark
_pure_set_default pure_color_k8s_context pure_color_success
_pure_set_default pure_color_k8s_namespace pure_color_primary
2 changes: 1 addition & 1 deletion functions/_pure_k8s_context.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function _pure_k8s_context
kubectl config current-context
kubectl config current-context 2>/dev/null
end
2 changes: 1 addition & 1 deletion functions/_pure_k8s_namespace.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function _pure_k8s_namespace
kubectl config view --minify --output 'jsonpath={..namespace}'
kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null
end
13 changes: 10 additions & 3 deletions functions/_pure_prompt_k8s.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ function _pure_prompt_k8s
if set --query pure_enable_k8s;
and test "$pure_enable_k8s" = true;
and _pure_check_availability pure_enable_k8s kubectl
and test -n (_pure_k8s_context) # todo: use $(cmd) syntax when Fish 3.3.1 is dropped

set -l context (_pure_set_color $pure_color_k8s_context)(_pure_k8s_context)
set -l namespace (_pure_set_color $pure_color_k8s_namespace)(_pure_k8s_namespace)
echo "$pure_symbol_k8s_prefix $context/$namespace"
set --local symbol (_pure_set_color $pure_color_k8s_prefix)$pure_symbol_k8s_prefix
set --local context (_pure_set_color $pure_color_k8s_context)(_pure_k8s_context)
set --local namespace (_pure_set_color $pure_color_k8s_namespace)(_pure_k8s_namespace)

if test -n "$namespace"
set --local namespace (_pure_set_color $pure_color_k8s_namespace)default
end

echo "$symbol $context/$namespace"
end
end
6 changes: 6 additions & 0 deletions tests/_pure.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ before_all
echo $pure_symbol_k8s_prefix
) = "☸"

@test "configure: pure_color_k8s_prefix" (
set --erase pure_color_k8s_prefix
source (status dirname)/../conf.d/pure.fish
echo $pure_color_k8s_prefix
) = pure_color_dark

@test "configure: pure_color_k8s_context" (
set --erase pure_color_k8s_context
source (status dirname)/../conf.d/pure.fish
Expand Down
Loading