aboutsummaryrefslogtreecommitdiff
path: root/scripts/commit-md
blob: 91610b6da0715bcc6d84bc86a4ca231e18237044 (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
#!/bin/sh
set -eu

LAST_COMMIT="$(git rev-parse HEAD)"
COMMIT="${1:-$LAST_COMMIT}"
REPOSITORY="$(basename "$PWD")"

usage() {
	cat <<EOF
Usage:
	$0 [COMMIT]
EOF
}

if [ -z "$COMMIT" ]; then
	echo "Missing \$COMMIT argument"
	usage >&2
	exit 2
fi

LINK="$(printf 'https://git.euandreh.xyz/%s/commit/?id=%s' "$REPOSITORY" "$COMMIT")"
MD="$(printf '[`%s`](%s)' "$COMMIT" "$LINK")"

xdg-open "$LINK"
printf '%s' "$MD" | xclip -sel clip
printf 'Copied %s to the clipboard!\n' "$MD" >&2