Skip to content

Instantly share code, notes, and snippets.

@emnsen
Created December 8, 2020 14:15
Show Gist options
  • Save emnsen/a6aedfb2757b456c61b478b796e1277a to your computer and use it in GitHub Desktop.
Save emnsen/a6aedfb2757b456c61b478b796e1277a to your computer and use it in GitHub Desktop.
#! /bin/bash
RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
step="$1"
if [ -z "$1" ]
then
step=patch
fi
base="$2"
if [ -z "$2" ]
then
base=$(git tag 2>/dev/null| tail -n 1)
if [ -z "$base" ]
then
base=1.0.0
fi
fi
MAJOR=`echo $base | sed -e "s#$RE#\1#"`
MINOR=`echo $base | sed -e "s#$RE#\2#"`
PATCH=`echo $base | sed -e "s#$RE#\3#"`
case "$step" in
major)
let MAJOR+=1
;;
minor)
let MINOR+=1
;;
patch)
let PATCH+=1
;;
esac
echo "$MAJOR.$MINOR.$PATCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment