Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lamlion/5d9224d389b211b5d4fb0bc37dfb9bfe to your computer and use it in GitHub Desktop.
Save lamlion/5d9224d389b211b5d4fb0bc37dfb9bfe to your computer and use it in GitHub Desktop.
Custom prompt showing the current Docker context configured using environment variables. ZSH theme is "agnoster". This gist is not the whole zshrc file, only the relevant parts.
ZSH_THEME="agnoster"
plugins=(git docker docker-compose)
prompt_docker_host() {
docker_icon="\xF0\x9F\x90\xB3"
if [[ -n "$DOCKER_HOST" ]]; then
if [[ -n "$DOCKER_CONTEXT_HOST" ]] && [[ "$DOCKER_CONTEXT_HOST" == "$DOCKER_HOST" ]]; then
prompt_segment red default "$docker_icon $DOCKER_CONTEXT"
else
prompt_segment red default "$docker_icon $DOCKER_HOST"
fi
elif [[ -n "$DOCKER_CONTEXT" ]]; then
prompt_segment red default "$docker_icon $DOCKER_CONTEXT"
fi
}
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
prompt_context
prompt_dir
prompt_git
prompt_docker_host
prompt_end
echo
echo " » "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment