From 2f4249cac9aa299fd3e2c36b7b6e17c19ff92854 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 11 May 2018 10:21:09 +0000 Subject: [PATCH] Kubernetes stuff. --- .profile.d/k8s.bashrc | 33 +++++++++++++++++++++++++++++++++ .ps1.d/k8s.ps1 | 15 +++++++++++++++ opt/bin/kubectl | 9 +++++++++ 3 files changed, 57 insertions(+) create mode 100644 .profile.d/k8s.bashrc create mode 100644 .ps1.d/k8s.ps1 create mode 100755 opt/bin/kubectl diff --git a/.profile.d/k8s.bashrc b/.profile.d/k8s.bashrc new file mode 100644 index 0000000..635e92e --- /dev/null +++ b/.profile.d/k8s.bashrc @@ -0,0 +1,33 @@ +function __k8s() { + local text= + if [ -n "$KUBECTL_NAMESPACE" ]; then + if [ ! "$KUBECTL_NAMESPACE" = "default" ]; then + echo -n "$1$KUBECTL_NAMESPACE" + return 0 + fi + fi +} + +function context() { + if [ "$1" = "reset" ]; then + unset KUBECTL_CONTEXT + elif [ -n "$1" ]; then + export KUBECTL_CONTEXT=$1 + elif [ -n "$KUBECTL_CONTEXT" ]; then + echo "$KUBECTL_CONTEXT" + else + kubectl config current-context + fi +} + +function namespace() { + if [ "$1" = "reset" ]; then + unset KUBECTL_NAMESPACE + elif [ -n "$1" ]; then + export KUBECTL_NAMESPACE=$1 + elif [ -n "$KUBECTL_NAMESPACE" ]; then + echo "$KUBECTL_NAMESPACE" + else + return 1 + fi +} diff --git a/.ps1.d/k8s.ps1 b/.ps1.d/k8s.ps1 new file mode 100644 index 0000000..d572afc --- /dev/null +++ b/.ps1.d/k8s.ps1 @@ -0,0 +1,15 @@ +#!/bash + +# This part of the prompt is taken from k8s.bashrc. +# It is shown only if __ps1_k8s is 1. By default it is 0. + +__ps1_k8s=${__ps1_k8s:-0} +__ps1_k8s_colour256="0;38;5;127" +__ps1_k8s_colour88="0;38;5;49" +__ps1_k8s_colour="0;35" + +function __ps1_k8s() { + [ "$__ps1_k8s" = "1" ] || return $1 + __k8s "$(__ps1_prefix $1 __ps1_k8s)" + return $1 +} diff --git a/opt/bin/kubectl b/opt/bin/kubectl new file mode 100755 index 0000000..3faadd2 --- /dev/null +++ b/opt/bin/kubectl @@ -0,0 +1,9 @@ +#!/bin/bash + +cmd=/usr/bin/kubectl +args="" + +[ -n "$KUBECTL_CONTEXT" ] && args="$args --context $KUBECTL_CONTEXT" +[ -n "$KUBECTL_NAMESPACE" ] && args="$args --namespace $KUBECTL_NAMESPACE" + +exec $cmd $args ${1+"$@"} -- 2.20.1