Skip to content

Instantly share code, notes, and snippets.

@r2DoesInc
Created June 2, 2014 14:32
Show Gist options
  • Select an option

  • Save r2DoesInc/0139fc3e6e6b19adcbb2 to your computer and use it in GitHub Desktop.

Select an option

Save r2DoesInc/0139fc3e6e6b19adcbb2 to your computer and use it in GitHub Desktop.

Revisions

  1. Ken created this gist Jun 2, 2014.
    25 changes: 25 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/sh
    #Define Manifest file and current versionCode.
    manf=AndroidManifest.xml
    versCode=`sed -n '/versionCode=/s/.*"\([0-9][0-9]*\)".*/\1/p' $manf`

    #versionCode is a number, so simply add 1.
    newVersCode=$((versCode + 1))

    #Swap old versionCode with new versionCode and write it to the file
    sed /versionCode=/s/'"'$versCode'"'/'"'$newVersCode'"'/ $manf >new$manf && cp new$manf $manf && rm -f new$manf
    echo versionCode=$newVersCode

    #Get the versoinName string
    versName=`sed -n '/versionName=/s/ android:versionName="//p' $manf`

    #Since the versionName is actually a string, we only want to bump the last number.
    versName=`echo $versName| cut -f1 -d"\""`
    lastPlace=${versName#${versName%?}}
    newLast=$((lastPlace + 1))
    newVersName="${versName%?}$newLast"
    sed /versionName=/s/'"'$versName'"'/'"'$newVersName'"'/ $manf >new$manf && cp new$manf $manf && rm -f new$manf
    echo versionName=$newVersName

    #Add new changes so they are included.
    git add $PWD/.