Skip to content

Instantly share code, notes, and snippets.

@msiegenthaler
Last active September 16, 2024 13:57

Revisions

  1. msiegenthaler revised this gist Jun 29, 2018. 2 changed files with 10 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion k.fish
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function k
    function k --wraps kubectl
    set -l cmd
    if test -n "$argv"
    set cmd $argv
    9 changes: 9 additions & 0 deletions secret.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function secret
    set -l secret $argv[1]
    set -l value $argv[2]
    if test -z $secret; or test -z $value
    echo "Usage: secret <secret> <value>"
    return 121
    end
    k get secret "$secret" -o jsonpath=\{.data.$value\} | base64 -d
    end
  2. msiegenthaler revised this gist Jun 29, 2018. 2 changed files with 19 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions enable_kubernetes.fish
    Original file line number Diff line number Diff line change
    @@ -13,10 +13,11 @@ function kubernetes_status
    return
    end

    set -l ns (kubectl config view -o json | jq --arg context $context -r '.contexts[] | select(.name | contains($ctx)) | .context.namespace')
    set -l ns $namespace
    [ -z $ns ]; and set -l ns (kubectl config view -o json | jq --arg context $ctx -r '.contexts[] | select(.name | contains($context)) | .context.namespace')
    [ -z $ns ]; and set -l ns 'default'

    echo (set_color 999999)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
    echo (set_color 666666)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
    end

    function enable_kubernetes
    16 changes: 16 additions & 0 deletions k.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function k
    set -l cmd
    if test -n "$argv"
    set cmd $argv
    else if [ (tput cols) -lt 150 ]
    set cmd get pod
    else
    set cmd get pod -o wide
    end

    if test -n "$namespace"
    kubectl --namespace "$namespace" $cmd
    else
    kubectl $cmd
    end
    end
  3. msiegenthaler renamed this gist Jun 28, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. msiegenthaler revised this gist Jun 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kubernetes_ctx_ns.fish
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ function kubernetes_status
    return
    end

    set -l ns (kubectl config view -o json | jq --arg context $context -r '.contexts[] | select(.name | contains($context)) | .context.namespace')
    set -l ns (kubectl config view -o json | jq --arg context $context -r '.contexts[] | select(.name | contains($ctx)) | .context.namespace')
    [ -z $ns ]; and set -l ns 'default'

    echo (set_color 999999)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
  5. msiegenthaler revised this gist Jun 28, 2018. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions kubernetes_ctx_ns.fish
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function kubectl_status
    function kubernetes_status
    [ -z "$KUBECTL_PROMPT_SEPARATOR" ]; and set -l KUBECTL_PROMPT_SEPARATOR "/"
    set -l config $KUBECONFIG
    [ -z "$config" ]; and set -l config "$HOME/.kube/config"
    @@ -19,6 +19,8 @@ function kubectl_status
    echo (set_color 999999)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
    end

    function fish_right_prompt
    echo (kubectl_status)
    function enable_kubernetes
    function fish_right_prompt
    echo (kubernetes_status)
    end
    end
  6. msiegenthaler created this gist Jun 28, 2018.
    24 changes: 24 additions & 0 deletions kubernetes_ctx_ns.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    function kubectl_status
    [ -z "$KUBECTL_PROMPT_SEPARATOR" ]; and set -l KUBECTL_PROMPT_SEPARATOR "/"
    set -l config $KUBECONFIG
    [ -z "$config" ]; and set -l config "$HOME/.kube/config"
    if [ ! -f $config ]
    echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no config"
    return
    end

    set -l ctx (kubectl config current-context 2>/dev/null)
    if [ $status -ne 0 ]
    echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no context"
    return
    end

    set -l ns (kubectl config view -o json | jq --arg context $context -r '.contexts[] | select(.name | contains($context)) | .context.namespace')
    [ -z $ns ]; and set -l ns 'default'

    echo (set_color 999999)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
    end

    function fish_right_prompt
    echo (kubectl_status)
    end