Skip to content

Instantly share code, notes, and snippets.

@rimelek
Created December 30, 2022 20:30
Show Gist options
  • Save rimelek/823c4fb3651cfcb88fbdc0e497c6ae84 to your computer and use it in GitHub Desktop.
Save rimelek/823c4fb3651cfcb88fbdc0e497c6ae84 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