-
-
Save electron0zero/7685fca7c2ae4d0cd355aa670675b65f to your computer and use it in GitHub Desktop.
Display the current git branch in your command prompt with username and dir., Adds an asterisk if there are unstaged updates.
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
# Add this to your .bashrc | |
# Will produce command line prompts like in git repositories | |
# <username>@<hostname>:<directory>(branch) $ | |
# and like this elsewhere. | |
# <username>@<hostname>:<directory> $ | |
# If there are unstaged changes in the repository, there will be an asterisk next to the branch name: | |
# <username>@<hostname>:<directory>(branch) $ | |
# taken from https://gist.github.com/johnpbloch/3406013 | |
# Trim path https://unix.stackexchange.com/a/26950/270668 | |
export PROMPT_DIRTRIM=1 | |
parse_git_branch() { | |
hasmod="" | |
if [[ $(git ls-files -dmo --exclude-standard 2> /dev/null) ]]; then | |
hasmod="*" | |
fi | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \\(.*\\)/(\\1$hasmod)/" | |
} | |
export PS1="\[\e[46m\]\[\e[30m\]\\u@\\h\[\e[01;00m\]:\[\e[43m\]\[\e[30m\]\\w\[\e[42m\]\[\e[30m\]\$(parse_git_branch)\[\e[01;00m\] $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment