Created
January 19, 2016 12:32
-
-
Save srdjanmarjanovic/99a26db1b6ababe49379 to your computer and use it in GitHub Desktop.
Useful script for naming branches for Git flow
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 | |
type="$1" | |
title="$2" | |
max_length="${3:-150}" | |
slug="$({ | |
tr '[A-Z]' '[a-z]' | tr -cs '[[:alnum:]]' '-' | |
} <<< "$title")" | |
slug="$({ | |
tr '[ČčĆć]' 'c' | |
} <<< "$slug")" | |
slug="$({ | |
sed 's/[Đđ]/dj/g' | |
} <<< "$slug")" | |
slug="$({ | |
tr '[Žž]' 'z' | |
} <<< "$slug")" | |
slug="$({ | |
tr '[Šš]' 's' | |
} <<< "$slug")" | |
slug="${slug##-}" | |
slug="${slug%%-}" | |
slug="${slug:0:$max_length}" | |
echo "$type/#$slug" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use:
/home/srdjan/slugify.bash
or/Users/srdjan
.bash_aliases
or.bash_profile
filealias slugify='sh ~/slugify.bash'
or whatever alias pleases yousource ~/.bash_aliases
orsource ~/.bash_profile
so alias can be usedslugify "TYPE" "NAME"
where TYPE is something like bug, feature, improvement and NAME is something like task name from project management toolhere is an example from Active Collab:
slugify "improvement" "#723: Kada se podesi Task ID in Lists na Visible, format prikaza nije ispravan"
wil output
improvement/#723-kada-se-podesi-task-id-in-lists-na-visible-format-prikaza-nije-ispravan
Want to create a git branch out of a slug in one line? No problem
slugify "improvement" "#723: Kada se podesi Task ID in Lists na Visible, format prikaza nije ispravan" | xargs git checkout -b
This command will make the appropriate name for the branch, create the branch, and checkout to it
Note: this script will replace characters
ŠĐČĆŽ šđčćž
withs dj c c z
and it will truncate NAME parameter to 150 characters