aboutsummaryrefslogtreecommitdiff
path: root/src/bin/commit-md
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-01-04 15:41:32 -0300
committerEuAndreh <eu@euandre.org>2022-01-04 15:41:32 -0300
commit8b9a649ac05469881e17a63112cef69bdc19ed08 (patch)
tree8d75b443361d9dbb85ca2a26c54c9d32cc019034 /src/bin/commit-md
parent.gitignore: Remove /cron/generated/ (diff)
downloaddotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.gz
dotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.xz
scripts/: Move executables to src/bin/, and add a proper CLI interface to them
Diffstat (limited to 'src/bin/commit-md')
-rwxr-xr-xsrc/bin/commit-md59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/bin/commit-md b/src/bin/commit-md
new file mode 100755
index 00000000..3d4d5f6a
--- /dev/null
+++ b/src/bin/commit-md
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ commit-md [COMMIT]
+ commit-md -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+COMMIT="${1:-$(git rev-parse HEAD)}"
+REPOSITORY="$(basename "$PWD")"
+
+LINK="$(printf 'https://euandreh.xyz/%s.git/commit/?id=%s' "$REPOSITORY" "$COMMIT")"
+# shellcheck disable=2016
+MD="$(printf '[`%s`](%s)' "$COMMIT" "$LINK")"
+
+xdg-open "$LINK"
+printf ' Done in\n%s.' "$MD" | xclip -sel clip
+printf 'Copied %s to the clipboard!\n' "$MD" >&2