Last active
October 9, 2015 13:47
-
-
Save andreineculau/3517110 to your computer and use it in GitHub Desktop.
JIRA ticket to branch name
This file contains 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
#!/bin/bash -e | |
# Usage # copy from browser "JIRA-205\nTicket title" | |
# $ jira2branch # echoes jira-205-ticket-title | |
# $ JIRA2BRANCH_TEAM=team jira2branch # echoes jira-205-team-ticket-title | |
# $ jira2branch team2 # override mode | |
# echoes jira-205-team2-ticket-title ignoring $JIRA2BRANCH_TEAM | |
OS=`uname` | |
function paste() { | |
if [ $OS == "Darwin" ]; then | |
echo "$(pbpaste -prefer txt)" | |
elif [ $OS == "Linux" ]; then | |
echo "$(xclip -o)" | |
fi | |
} | |
KEYWORD="${1:-$JIRA2BRANCH_TEAM}" | |
CLEAN="$(paste)" | |
# no new lines | |
CLEAN=`echo -ne "$CLEAN" | tr "\n" "|"` | |
CLEAN=${CLEAN/|/-$KEYWORD-/} | |
# all alphanumeric or hyphens | |
CLEAN=${CLEAN//[^a-zA-Z0-9]/-} | |
CLEAN=`echo -ne "$CLEAN" | tr -s "-"` | |
# all lowercase | |
CLEAN=`echo -ne "$CLEAN" | tr "[A-Z]" "[a-z]"` | |
echo ${CLEAN:0:75} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment