summaryrefslogtreecommitdiff
path: root/fish/conf.d/k8s.fish
blob: ee1584bf5019254ffc6a2271b20a96dde7374ec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function kcompletions
    if command -q -v kubectl >/dev/null
        kubectl completion fish | source
    end
end

# Check if the directory $HOME/.krew exists and update PATH
if test -d $HOME/.krew
    set -x PATH (set -q KREW_ROOT; and echo $KREW_ROOT; or echo $HOME/.krew)/bin $PATH
end

function kpod
    set pattern "."
    if test -n "$argv[1]"
        set pattern "$argv[1]"
    end
    set -gx POD (kubectl get pods | grep "$pattern" | sort -R | head -n 1 | cut -d' ' -f1)
    echo "Pod is $POD"
end

function klogsf
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl logs -f $POD
end

function klogs
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl logs $POD
end

function kbash
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl exec -it $POD -- /bin/bash
end

function kshell
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl exec -it $POD -- /bin/sh
end

function kdesc
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl describe pod $POD
end

function kedit
    if test -z "$POD" -o -n "$argv[1]"
        kpod $argv
    end
    kubectl edit pod $POD
end

function k8s::kubectl::config::contexts
    kubectl config get-contexts | sed '1d; /\*/d' | awk '{ print $1 }' | sort
end
alias kcontexts="k8s::kubectl::config::contexts"

function k8s::kubectl::config::use_context
    kubectl config use-context (kubectl config get-contexts | sed '1d; /\*/d' | awk '{ print $1 }' | sort | fzf)
end
alias kcontext="k8s::kubectl::config::use_context"

function k8s::kubectl::config::set_namespace
    kubectl config set-context --current --namespace=(kubectl get ns | sed 1d | awk '{ print $1 }' | sort | fzf)
end
alias knamespace="k8s::kubectl::config::set_namespace"