Skip to content

Instantly share code, notes, and snippets.

@gorangajic
Forked from srdjanmarjanovic/slugify.bash
Last active April 4, 2022 23:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gorangajic/d80ab40e1b6c70f67afb to your computer and use it in GitHub Desktop.
Save gorangajic/d80ab40e1b6c70f67afb to your computer and use it in GitHub Desktop.
Useful script for naming branches for Git flow
#!/bin/bash
slugify() {
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}"
git checkout -b "$type/#$slug"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment