Kubernetes stuff. master
authorIain Patterson <me@iain.cx>
Fri, 11 May 2018 10:21:09 +0000 (10:21 +0000)
committerIain Patterson <me@iain.cx>
Thu, 17 May 2018 13:22:17 +0000 (14:22 +0100)
.profile.d/k8s.bashrc [new file with mode: 0644]
.ps1.d/k8s.ps1 [new file with mode: 0644]
opt/bin/kubectl [new file with mode: 0755]

diff --git a/.profile.d/k8s.bashrc b/.profile.d/k8s.bashrc
new file mode 100644 (file)
index 0000000..635e92e
--- /dev/null
@@ -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 (file)
index 0000000..d572afc
--- /dev/null
@@ -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 (executable)
index 0000000..3faadd2
--- /dev/null
@@ -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+"$@"}