Skip to content

Instantly share code, notes, and snippets.

@micahhausler
Created October 10, 2016 13:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save micahhausler/0d8646da95ad0a258fb8a6521fc35224 to your computer and use it in GitHub Desktop.
Save micahhausler/0d8646da95ad0a258fb8a6521fc35224 to your computer and use it in GitHub Desktop.
Kubernetes PS1
NORMAL="\[\033[00m\]"
BLUE="\[\033[01;34m\]"
RED="\[\e[1;31m\]"
YELLOW="\[\e[1;33m\]"
GREEN="\[\e[1;32m\]"
PS1_WORKDIR="\w"
PS1_HOSTNAME="\h"
PS1_USER="\u"
__kube_ps1()
{
CONTEXT=$(kubectl config current-context)
if [ -n "$CONTEXT" ]; then
case "$CONTEXT" in
*prod*)
echo "${RED}(k8s: ${CONTEXT})"
;;
*test*)
echo "${YELLOW}(k8s: ${CONTEXT})"
;;
*)
echo "${GREEN}(k8s: ${CONTEXT})"
;;
esac
fi
}
export PROMPT_COMMAND='PS1="${GREEN}${PS1_USER}@${PS1_HOSTNAME}${NORMAL}:$(__kube_ps1)${BLUE}${PS1_WORKDIR}${NORMAL}\$ "'
# See https://twitter.com/micahhausler/status/785204875613261824 for example output
@micahhausler
Copy link
Author

screen shot 2016-10-09 at 2 43 43 pm

@treed
Copy link

treed commented Oct 11, 2016

For those who like fancy unicode stuff in their prompt, ☸ looks sorta like the Kubernetes logo, especially when colored correctly.

@treed
Copy link

treed commented Oct 11, 2016

@so0k
Copy link

so0k commented Oct 28, 2016

or you can ⌃+⌘+SPACE then type helm and get: ⎈

@so0k
Copy link

so0k commented Oct 28, 2016

forked powerline-docker and created https://github.com/so0k/powerline-kubernetes

@so0k
Copy link

so0k commented Mar 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment