-
-
Save djui/3518790 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 # 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