about summary refs log tree commit diff stats
path: root/build/latex/academia/scripts/cprh.sh
blob: 95825750f10e02bed24883cc4eacffb3c75675e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env sh

die() {
    echo "$@" 1>&2
    exit 1
}

help() {
    cat <<EOF
A copyright header managment tool.

USAGE:
    cprh.sh [OPTIONS] contribute NAME EMAIL FILE..

OPTIONS:
    --help      | -h
                            Display this help and exit.

ARGUMENTS:
    NAME := [[git config user.name]]
                            Your name.

    NAME := [[git config user.email]]
                            Your email address.

    FILE := [[git diff --name-only --cached]]
                            The file you want to change. This can be given multiple times.
EOF
}

for arg in "$@"; do
    case "$arg" in
    "--help" | "-h")
        help
        exit 0
        ;;
    *)
        echo "'$1' is not a recognized option. See --help for more!" 1>&2
        exit 1
        ;;
    esac
done

user_name="$1"
[ -z "$user_name" ] && die "No NAME set! See --help for more"

user_email="$2"
[ -z "$user_email" ] && die "No EMAIL set! See --help for more"
shift 2

styleOne=""
styleTwo=""
[ "$COMMENT_STYLE" ] && styleOne="--style" && styleTwo="$COMMENT_STYLE"

# The styleTwo must be unquoted to avoid adding empty args to reuse
# shellcheck disable=2086
reuse annotate --copyright "$user_name <$user_email>" --copyright-prefix string-c --template default --multi-line $styleOne $styleTwo