diff --git a/bin/git-changelog b/bin/git-changelog index af602ce..d305cc2 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -1,29 +1,44 @@ #!/bin/sh +FILE="" +LIST=false + +while [ "$1" != "" ]; do + case $1 in + -l | --list ) + LIST=true + ;; + * ) + FILE=$1 + ;; + esac + shift +done + DATE=`date +'%Y-%m-%d'` HEAD="\nn.n.n / $DATE \n==================\n\n" -case "$1" in - -l|--list) - version=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1)) - if test -z "$version"; then - git log --pretty="format: * %s" - else - git log --pretty="format: * %s" $version.. - fi - ;; - *) - CHANGELOG=$1 - if test "$CHANGELOG" = ""; then - CHANGELOG=`ls | egrep 'change|history' -i` - if test "$CHANGELOG" = ""; then CHANGELOG='History.md'; fi - fi - tmp="/tmp/changelog" - printf "$HEAD" > $tmp - git-changelog --list >> $tmp - printf '\n' >> $tmp - if [ -f $CHANGELOG ]; then cat $CHANGELOG >> $tmp; fi - mv $tmp $CHANGELOG - test -n "$EDITOR" && $EDITOR $CHANGELOG - ;; -esac +if $LIST; then + version=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1)) + if test -z "$version"; then + git log --pretty="format: * %s" + else + git log --pretty="format: * %s" $version.. + fi + exit +fi + +CHANGELOG=$FILE +if test "$CHANGELOG" = ""; then + CHANGELOG=`ls | egrep 'change|history' -i` + if test "$CHANGELOG" = ""; then + CHANGELOG='History.md'; + fi +fi +tmp="/tmp/changelog" +printf "$HEAD" > $tmp +git-changelog --list >> $tmp +printf '\n' >> $tmp +if [ -f $CHANGELOG ]; then cat $CHANGELOG >> $tmp; fi +mv $tmp $CHANGELOG +test -n "$EDITOR" && $EDITOR $CHANGELOG