Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Forked from andreineculau/jira2branch.sh
Created March 22, 2013 09:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriid/5220054 to your computer and use it in GitHub Desktop.
Save dmitriid/5220054 to your computer and use it in GitHub Desktop.
#!/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