Context Aware Prompt

Opensource ByJG GitHub source GitHub license


This project is a fork from initialy focused only in the Git context.

There are several command line tools that uses some context and for many times can lead us to errors if we don't pay attention for the context we are executing those commands.

For example, constantly switching git branches can be confusing though as you have to run git status to see which branch you're currently on. The same for the current kubernetes context we are using. If we are working with multiples cluster and namespaces we can apply or delete a configuration in the wrong cluster and you have to run kubectl config current-context to see the context you are.

The solution to this is to have your terminal prompt display the current branch. There's a number of articles available online about how to achieve this. This project is an attempt to make an easy to install/configure solution.

Contexts Prompts Available

  • Current Git Branch
  • Current Working Directory has changes or is ahead or behind the server
  • Cluster name and branch of the active Kubernetes config


If you cd to a Git working directory, you will see the current Git branch name displayed in your terminal prompt. When you're not in a Git working directory, your prompt works like normal.

The same if you have a KUBECONFIG environment variable set or a file ~/.kube/config/

Git Branch in Prompt



wget -qO- | bash

If you want to install only git or only k8s context prompts just call:

wget -qO- | bash -s git


wget -qO- | bash -s k8s

Detailed instructions

Clone the project to a .bash folder in your home directory:

mkdir ~/.bash
cd ~/.bash
git clone git://

Edit your ~/.bash_profile or ~/.profile and add the following to the top:

export CONTEXT_AWARE_PROMPT=~/.bash/context-aware-prompt

Once installed, there will be new $git_branch, $git_dirty and k8s_config variables available to use in the PS1 environment variable, along with a number of color helper variables which you can see a list of in

If you want to know more about how to customize your prompt, I recommend this article: How to: Change / Setup bash custom prompt (PS1)

Suggested Prompts

Below are a few suggested prompt configurations. Simply paste the code at the end of the same file you pasted the installation code into earlier.

Mac OS X

export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "

Optionally, if you want a nice pretty prompt when using sudo -s, also add this line:

export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "



export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w \[$txtylw\]\$k8s_config\[$txtrst\]\[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "


export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtylw\]\$k8s_config\[$txtrst\]\[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "


Assuming you followed the default installation instructions and cloned this repo to ~/.bash/context-aware-prompt:

cd ~/.bash/context-aware-prompt
git pull

Reconfigure / Uninstall

If you installed using the you can remove the configuration and call the install with the new configuration:

# Uninstall

# Add new configuration
~/.bash/context-aware-prompt/ [git|k8s|all]


CC0 1.0 Universal

Open source ByJG