-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67c2b9c
commit c096422
Showing
2 changed files
with
83 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Inspired from: | ||
# https://github.com/jonmosco/kube-ps1 | ||
# https://github.com/Ladicle/fish-kubectl-prompt | ||
|
||
function __kube_ps_update_cache | ||
function __kube_ps_cache_context | ||
set -l ctx (kubectl config current-context 2>/dev/null) | ||
if test $status -eq 0 | ||
set -g __kube_ps_context "$ctx" | ||
else | ||
set -g __kube_ps_context "n/a" | ||
end | ||
end | ||
|
||
function __kube_ps_cache_namespace | ||
set -l ns (kubectl config view --minify -o 'jsonpath={..namespace}' 2>/dev/null) | ||
if test -n "$ns" | ||
set -g __kube_ps_namespace "$ns" | ||
else | ||
set -g __kube_ps_namespace "default" | ||
end | ||
end | ||
|
||
function __stat_mtime | ||
#-- cross-platform workaround; POSIX didn't specify stat(1) and so | ||
#-- its interface is incompatibly different on Mac OS and Linux. | ||
#-- see https://unix.stackexchange.com/q/561927/3097 | ||
python -c "print(__import__('os').stat(__import__('sys').argv[1]).st_mtime)" $argv | ||
end | ||
|
||
set -l kubeconfig "$KUBECONFIG" | ||
if test -z "$kubeconfig" | ||
set kubeconfig "$HOME/.kube/config" | ||
end | ||
|
||
if test "$kubeconfig" != "$__kube_ps_kubeconfig" | ||
__kube_ps_cache_context | ||
__kube_ps_cache_namespace | ||
set -g __kube_ps_kubeconfig "$kubeconfig" | ||
set -g __kube_ps_timestamp (date +%s) | ||
return | ||
end | ||
|
||
for conf in (string split ':' "$kubeconfig") | ||
if test -r "$conf" | ||
if test -z "$__kube_ps_timestamp"; or test (__stat_mtime "$conf") -gt "$__kube_ps_timestamp" | ||
__kube_ps_cache_context | ||
__kube_ps_cache_namespace | ||
set -g __kube_ps_kubeconfig "$kubeconfig" | ||
set -g __kube_ps_timestamp (date +%s) | ||
return | ||
end | ||
end | ||
end | ||
end | ||
|
||
function __kube_prompt | ||
if test -z "$__kube_ps_enabled"; or test $__kube_ps_enabled -ne 1 | ||
return | ||
end | ||
|
||
__kube_ps_update_cache | ||
echo -n -s " (⎈ $__kube_ps_context|$__kube_ps_namespace)" | ||
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,19 @@ | ||
function kube_ps -a toggle | ||
if test "$toggle" = "on" | ||
set -U __kube_ps_enabled 1 | ||
return | ||
end | ||
|
||
if test "$toggle" = "off" | ||
set -U __kube_ps_enabled 0 | ||
return | ||
end | ||
end | ||
|
||
function dcleanup | ||
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null | ||
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null | ||
return | ||
end | ||
|
||
|