kube-tmux: Kubernetes context and namespace status for tmux

June 26, 2025 · View on GitHub

A script that lets you add the current Kubernetes context and namespace configured on kubectl to your tmux status line.

Inspired by kube-ps1, this is a port to tmux that includes all the features that make kube-ps1 efficient and brings it to the tmux status line.

plugin

Disclaimer

This plugin is actively under development, with lots of updates on the way — including a full restructure to work with TPM, tons of bug fixes, and style improvements. Expect frequent changes. Some updates might break things here and there, but I’ll be quick to patch them.

If you have any bug reports, please feel free to submit a PR, or a bug report.

Installing

Manual

Clone this repository to your $HOME/.tmux directory, and add the following line to your ~/.tmux.conf:

set -g status-right "#(/bin/bash $HOME/.tmux/kube-tmux/kube.tmux 250 red cyan)"

250 is the color selection for the default foreground, red for the context, and cyan for the namespace.

set -g @plugin 'tmux-plugins/tpm' # mandatory
set -g @plugin 'jonmosco/kube-tmux'

Requirements

  • tmux
  • kubectl and/or oc

Plugin Structure

The default plugin layout is:

<symbol> <cluster>:<namespace>

If the current-context is not set, kube-tmux will return the following:

<symbol> N/A:N/A

Customization

The default color for the context are red, and cyan for the namespace Colors for the default text, context, and namespace can be changed:

#(/bin/bash $HOME/.tmux/kube-tmux/kube.tmux text context namespace)

Customize display of cluster name and namespace

You can change how the cluster name and namespace are displayed using the KUBE_TMUX_CLUSTER_FUNCTION and KUBE_TMUX_NAMESPACE_FUNCTION variables respectively.

For the following examples let's assume the following:

cluster name: sandbox.k8s.example.com
namespace: alpha

If you're using domain style cluster names, your prompt will get quite long very quickly. Let's say you only want to display the first portion of the cluster name (sandbox), you could do that by adding the following:

function get_cluster_short() {
    echo "\$1" | cut -d . -f1
}

export KUBE_TMUX_CLUSTER_FUNCTION=get_cluster_short

The same pattern can be followed to customize the display of the namespace. Let's say you would prefer the namespace to be displayed in all uppercase (ALPHA), here's one way you could do that:

function get_namespace_upper() {
    echo "\$1" | tr '[:lower:]' '[:upper:]'
}

export KUBE_TMUX_NAMESPACE_FUNCTION=get_namespace_upper

Important:
These functions and environment variables must be defined and exported before kube-tmux is loaded in your tmux configuration. If you are using TPM, ensure you set these in your shell profile (e.g., .bashrc, .zshrc) or in a sourced script before launching tmux. If you are loading kube-tmux manually in your ~/.tmux.conf, set and export these variables/functions above the set -g status-right line.

Example for manual setup in ~/.tmux.conf:

# In your shell profile (before starting tmux)
function get_cluster_short() {
    echo "\$1" | cut -d . -f1
}
export KUBE_TMUX_CLUSTER_FUNCTION=get_cluster_short

# In your ~/.tmux.conf
set -g status-right "#(/bin/bash $HOME/.tmux/kube-tmux/kube.tmux 250 red cyan)"
VariableDefaultMeaning
KUBE_TMUX_CLUSTER_FUNCTIONNo default, must be user suppliedFunction to customize how cluster is displayed
KUBE_TMUX_NAMESPACE_FUNCTIONNo default, must be user suppliedFunction to customize how namespace is displayed