Last active
July 16, 2019 08:02
-
-
Save abn/28908becf5d34d473865 to your computer and use it in GitHub Desktop.
.bashrc snippet for displaying current branch when in repositories
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 some magic when in git repos | |
| GIT_SUFFIX=$(echo $PS1 | grep "__git_ps1") | |
| if [ -z "$GIT_SUFFIX" ]; then | |
| SRC=/usr/share/git-core/contrib/completion/git-prompt.sh | |
| if [ -f $SRC ]; then | |
| . $SRC | |
| fi | |
| PS1="$(echo $PS1 | sed s/']\\\$'//)\$(__git_ps1)]$ " | |
| fi | |
| function git-branch-prune() { | |
| local current_branch=$(git rev-parse --abbrev-ref HEAD) | |
| git fetch -p | |
| for r in $(git remote); do | |
| git remote prune ${r} | |
| done; | |
| git branch -vv | grep ': gone]' | awk '{print $1}' \ | |
| | grep -v "${current_branch}" \ | |
| | xargs -I {} git branch -D {} | |
| git branch -vv | cut -c 3- | awk '$3 !~/\[/ { print $1 }' \ | |
| | grep -v "${current_branch}" \ | |
| | xargs -I {} git branch -D {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment