#!/usr/bin/env bash
#
# Update copyright dates in new and modified files. Call without
# arguments to operate on uncommitted changes. Arguments will be passed
# to bzr status, so to operate on all new and modified files relative to
# the submit branch, use:
#
#   update-new-and-modified-copyright -r submit:
#

year="$(date +%Y)"

bzr status --short "$@" | \
    awk '/^.[MN] .*[.]py$/ { print $NF }' | xargs -r sed -ri \
    "1,2{/Copyright/s/(201[0-9])([, -]+201[0-9])?/\1-${year}/;s/${year}-${year}/${year}/}"
