Skip to content

Instantly share code, notes, and snippets.

@TheVaffel
Last active April 3, 2020 13:23
Show Gist options
  • Save TheVaffel/4a47f3e91c463be0ced2692998e8a8f9 to your computer and use it in GitHub Desktop.
Save TheVaffel/4a47f3e91c463be0ced2692998e8a8f9 to your computer and use it in GitHub Desktop.
Bash Prompt (Which, when I come to think of it, translates to "poo fart" in Norwegian)

Bash prompt with Git repository name and branch

Will give prompts of the form

host ~/working/dir $

when outside a Git repo, and of the form

host repository_name/path/from/repo/root (branch) $

when inside one.

Joyful colors included.

PS1='\[\e[1;32m\]\h `if git status > /dev/null 2>&1; \
then GITTOP=\`git rev-parse --show-toplevel\`; \
echo -e "\[\e[1;36m\]"\
\`basename $GITTOP\`\
"\[\e[1;33m\]"\
\/\`realpath --relative-to=$GITTOP .\` \
"\[\e[1;34m\]"\
\(\`git rev-parse --abbrev-ref HEAD 2> /dev/null\`\) ; \
else echo -e "\[\e[1;34m\]""\w"; fi` \$ \[\e[0m\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment