Created
September 28, 2011 11:09
-
-
Save FotoVerite/1247678 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# | |
# Usage: version [bump|minor|major] | |
# | |
# | |
# Increments Version or Shows latest version | |
# | |
version=$1 | |
get_version=$(git tag | grep ^v*[0-9].[0-9].[0-9] | tr -d '[[:alpha:]]' | tail -1 | sort -n ) | |
function getVersion { | |
echo "\nRepo's Current Version: " | |
echo | |
echo $get_version | |
exit 0 | |
} | |
function hasVersion { | |
if [ -z $get_version ]; then | |
echo "\nNo version set. Do you want to set version to 1.0.0 [Y/N]" | |
read answer | |
case $answer in | |
Y | y) | |
setVersion "1.0.0" | |
exit 0 | |
;; | |
N | n | * ) | |
echo exiting program | |
exit 0 | |
;; | |
esac | |
fi | |
} | |
function setVersion { | |
hasVersion | |
$(git tag -a "$1" -m "Version $1") | |
#$(git push --tags) | |
echo "Version set to $1" | |
} | |
if [ -z $version ]; then | |
getVersion | |
fi | |
for i in $* | |
do | |
case $i in | |
bump | -b) | |
setVersion $(echo $get_version | awk -F. '{$3+=1; OFS="."; print $0}') | |
;; | |
minor | -mn) | |
setVersion $(echo $get_version | awk -F. '{$3+=1; OFS="."; print $0}') | |
;; | |
major | -mj) | |
setVersion $(echo $get_version | awk -F. '{$3+=1; OFS="."; print $0}') | |
;; | |
-v | --version) | |
echo 1.0.0 | |
;; | |
*) | |
echo unknown option, please use major, minor, or bump | |
;; | |
esac | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment