Skip to content

Instantly share code, notes, and snippets.

@andreineculau
Last active October 9, 2015 13:47
Show Gist options
  • Save andreineculau/3517110 to your computer and use it in GitHub Desktop.
Save andreineculau/3517110 to your computer and use it in GitHub Desktop.
JIRA ticket to branch name
#!/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