Skip to content

Instantly share code, notes, and snippets.

@tyrelsouza
Last active August 29, 2015 14:21
Show Gist options
  • Save tyrelsouza/ffad8cf2790581ff82d7 to your computer and use it in GitHub Desktop.
Save tyrelsouza/ffad8cf2790581ff82d7 to your computer and use it in GitHub Desktop.
Copy git branch to your clipboard (needs xsel or pbcopy installed)
function cpbr {
if branch=$(git symbolic-ref --short -q HEAD)
then
if command -v pbcopy 2>/dev/null; then
printf "$branch" | pbcopy
echo "$branch copied to your clipboard using pbcopy"
elif command -v xsel 2>/dev/null; then
printf "$branch" | xsel --clipboard
echo "$branch copied to your clipboard using xsel"
else
echo "Please install xsel or pbcopy"
fi
else
echo "No branch, not copying"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment