From 49ef973cf441e8934e5efa4a6a3f0e3818ff5340 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Fri, 9 Sep 2022 22:13:52 -0400 Subject: [PATCH] acme: Update `Note` to append, add GitHub PR plumbing Fortunately, I'm not a heavy GitHub Issues user so '#123' always means "PR #123". Writing a plumbing script to open them was pretty easy! --- bin/acme-scripts/Note | 11 ++++++++++- bin/openpr | 22 ++++++++++++++++++++++ lib/plumbing | 5 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 bin/openpr diff --git a/bin/acme-scripts/Note b/bin/acme-scripts/Note index 585406f..1381123 100755 --- a/bin/acme-scripts/Note +++ b/bin/acme-scripts/Note @@ -1,3 +1,12 @@ #!/bin/sh name=${1:-scratch-$(/usr/bin/date +%F).txt} -(date; echo) | plumb -i -d edit -a "action=showdata filename=$HOME/notes/$name" + +file=$HOME/notes/$name + +if [ -e $file ]; then + # Just open the existing file! + plumb -d edit $file +else + # Open in a buffer but don't save to the file yet -- will likely rename! + (date; echo) | plumb -i -d edit -a "action=showdata filename=$HOME/notes/$name" +fi diff --git a/bin/openpr b/bin/openpr new file mode 100755 index 0000000..cc80406 --- /dev/null +++ b/bin/openpr @@ -0,0 +1,22 @@ +#!/bin/sh +# openpr -- open a pr from GitHub +set -e +die() { + echo "$*" 1>&2 + exit 1 +} + +[ -z "$1" ] && logger "openpr-die" && die "usage: openpr NUM" +logger "openpr: $1" + +logger "openpr-wdir: $wdir" +logger `pwd` +num=${1###} +logger "openpr-num: $num" + +url=$(git remote get-url origin | sed -e 's/^git@//' -e 's@:@/@' -e 's/\.git$//') + +logger "openpr-url: $url" +[ -z "$url" ] && die "not in a repo?" + +${BROWSER:-firefox} "https://$url/pull/$num" diff --git a/lib/plumbing b/lib/plumbing index 1f5f6dd..903ff9c 100644 --- a/lib/plumbing +++ b/lib/plumbing @@ -36,5 +36,10 @@ type is text data matches '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+' plumb start rc -c 'git -C '$wdir' show '$0' >[2=1] | plumb -i -d edit -a ''action=showdata filename=/'$wdir'/'$0'''' +# #PR numbers to openpr (for work) +type is text +data matches '#([0-9]+)' +plumb start rc -c 'cd '$wdir' && openpr '$1' + editor = acme include basic -- libgit2 1.1.1