Created
June 3, 2021 14:02
-
-
Save agambier/60ae730368f4ed23119db7fa7fdd3ad7 to your computer and use it in GitHub Desktop.
custom bash prompt with git branch displayed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Display the git branch if current folder is a git repo. | |
# the small square before the branch name is the unicdeo symbo \ue0a0 | |
# | |
# ┌─[user@host:folder git_branch] | |
# └> $ | |
# | |
# Install git-prompt.sh as ~/.git-prompt.sh (https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh) | |
# Add the following line in your ~/.bashrc | |
[ -f ~/.git-prompt.sh ] && source ~/.git-prompt.sh | |
__my_git_ps1(){ | |
[ -f ~/.git-prompt.sh ] && PS1_GIT=$(__git_ps1 "%s") || PS1_GIT='' | |
[ -n "$PS1_GIT" ] && PS1_GIT=$' \033[00;35m\ue0a0'$PS1_GIT$'\033[0;34m' | |
echo "$PS1_GIT" | |
} | |
# find the section settin up PS1 in a color terminal | |
# and replace PS1 with the one below | |
PS1='\[\033[0;34m\]┌─[\[\033[00;32m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\W$(__my_git_ps1)]\n└> \[\033[0;36m\]\$ \[\033[0m\]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment