Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Created June 22, 2022 04:40
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 hongkongkiwi/6f25010ba19d1eeaa0197222ec0c3fea to your computer and use it in GitHub Desktop.
Save hongkongkiwi/6f25010ba19d1eeaa0197222ec0c3fea to your computer and use it in GitHub Desktop.
One liner to format a git tag / branch name appropriately for a docker tag
# 1. Replace any non valid characters with dash
# 2. Remove any .- from start of name
# 3. Replace duplicate dash with a single one
# 3. Replace duplicate underscore with a single one
# 4. Replace duplicate dot with a single one
# 5. Truncate string to 128 chars (or less)
sed -e 's/[^[:alnum:]\.\_\-]/-/g' \
-e 's|^[.-]\+||g' \
-e 's|-\+|-|g' \
-e 's|_\+|_|g' \
-e 's|\.\+|.|g' \
-e 's/^\(.\{128\}\).*/\1/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment