Skip to content

Instantly share code, notes, and snippets.

@djui
Forked from andreineculau/jira2branch.sh
Created August 29, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djui/3518790 to your computer and use it in GitHub Desktop.
Save djui/3518790 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 # echoes jira-205-team-ticket-title
OS=`uname`
function paste() {
if [ $OS == "Darwin" ]; then
echo "$(pbpaste -prefer txt)"
elif [ $OS == "Linux" ]; then
echo "$(xclip -o)"
fi
}
KEYWORD="$1"
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:50}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment