Skip to content

Instantly share code, notes, and snippets.

@abn
Last active July 16, 2019 08:02
Show Gist options
  • Select an option

  • Save abn/28908becf5d34d473865 to your computer and use it in GitHub Desktop.

Select an option

Save abn/28908becf5d34d473865 to your computer and use it in GitHub Desktop.
.bashrc snippet for displaying current branch when in repositories
# 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