From b3e80152c8dbe9ea641ff4754af271fb57c7d21b Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 30 Aug 2022 23:29:08 -0400 Subject: [PATCH] acme: Add acme startup script and helper utils I've been mucking around with acme(1) again. Once you feel the power of the 3rd button plumb(7) it's just so hard to go back! This patch is my most serious attempt yet at integrating acme into my everyday work. It adds a startup script with the right env vars set so that other tools play nicely with the environment (i.e. inside a win(1) shell) and it adds several small helper tools to make working with git work well (it's the *perfect* plumber use case!). Of course, the plumber needs to be updated to understand git sha's, so I'm checking in the plumbing rules I'm using too! --- bin/a | 9 +++++++++ bin/acme-scripts/e | 3 +++ bin/acme-scripts/ga | 2 ++ bin/acme-scripts/gbl | 9 +++++++++ bin/acme-scripts/gc | 2 ++ bin/acme-scripts/gca | 2 ++ bin/acme-scripts/gd | 2 ++ bin/acme-scripts/gg | 4 ++++ bin/acme-scripts/gl | 5 +++++ bin/acme-scripts/glo | 2 ++ bin/acme-scripts/gls | 2 ++ bin/acme-scripts/gs | 2 ++ bin/acme-scripts/i+ | 2 ++ bin/acme-scripts/i- | 2 ++ bin/acme-scripts/jq | 3 +++ bin/acme-scripts/nas | 14 ++++++++++++++ bin/gg | 4 ---- lib/plumbing | 40 ++++++++++++++++++++++++++++++++++++++++ 18 files changed, 105 insertions(+), 4 deletions(-) create mode 100755 bin/a create mode 100755 bin/acme-scripts/e create mode 100755 bin/acme-scripts/ga create mode 100755 bin/acme-scripts/gbl create mode 100755 bin/acme-scripts/gc create mode 100755 bin/acme-scripts/gca create mode 100755 bin/acme-scripts/gd create mode 100755 bin/acme-scripts/gg create mode 100755 bin/acme-scripts/gl create mode 100755 bin/acme-scripts/glo create mode 100755 bin/acme-scripts/gls create mode 100755 bin/acme-scripts/gs create mode 100755 bin/acme-scripts/i+ create mode 100755 bin/acme-scripts/i- create mode 100755 bin/acme-scripts/jq create mode 100755 bin/acme-scripts/nas delete mode 100755 bin/gg create mode 100644 lib/plumbing diff --git a/bin/a b/bin/a new file mode 100755 index 0000000..e710995 --- /dev/null +++ b/bin/a @@ -0,0 +1,9 @@ +#!/bin/sh +export PAGER=nobs +export EDITOR=editinacme # from 9fans.net/go +unset VISUAL +export TERM=dumb +export NO_COLOR=1 +export SHELL=/usr/lib/plan9/bin/rc +export PATH="$(dirname "$(readlink -f "$0")")/acme-scripts:$PATH" +acme -f /mnt/font/GoMono/12a/font -a "$@" diff --git a/bin/acme-scripts/e b/bin/acme-scripts/e new file mode 100755 index 0000000..a7ca409 --- /dev/null +++ b/bin/acme-scripts/e @@ -0,0 +1,3 @@ +#!/bin/sh +# e -- shortcut for editinacme +exec editinacme "$@" diff --git a/bin/acme-scripts/ga b/bin/acme-scripts/ga new file mode 100755 index 0000000..0900b9a --- /dev/null +++ b/bin/acme-scripts/ga @@ -0,0 +1,2 @@ +#!/bin/sh +exec git add "$@" diff --git a/bin/acme-scripts/gbl b/bin/acme-scripts/gbl new file mode 100755 index 0000000..7f3a319 --- /dev/null +++ b/bin/acme-scripts/gbl @@ -0,0 +1,9 @@ +#!/bin/sh +# git blame, in acme! +if [ -z "$1" ]; then + echo "usage: gbl FILE" 1>&2 + exit 1 +fi + +file=$1 +git blame --date="short" "$file" | plumb -i -d edit -a "action=showdata filename=$file:BLAME" diff --git a/bin/acme-scripts/gc b/bin/acme-scripts/gc new file mode 100755 index 0000000..6243728 --- /dev/null +++ b/bin/acme-scripts/gc @@ -0,0 +1,2 @@ +#!/bin/sh +exec git commit "$@" diff --git a/bin/acme-scripts/gca b/bin/acme-scripts/gca new file mode 100755 index 0000000..ecf7559 --- /dev/null +++ b/bin/acme-scripts/gca @@ -0,0 +1,2 @@ +#!/bin/sh +exec git commit -a "$@" diff --git a/bin/acme-scripts/gd b/bin/acme-scripts/gd new file mode 100755 index 0000000..bea935d --- /dev/null +++ b/bin/acme-scripts/gd @@ -0,0 +1,2 @@ +#!/bin/sh +exec git diff "$@" diff --git a/bin/acme-scripts/gg b/bin/acme-scripts/gg new file mode 100755 index 0000000..467a521 --- /dev/null +++ b/bin/acme-scripts/gg @@ -0,0 +1,4 @@ +#!/bin/sh +# gg -- git grep with numbers. Not a git alias for use with acme(1) +# (which works best with commands with no spaces) +exec git grep -n "$@" diff --git a/bin/acme-scripts/gl b/bin/acme-scripts/gl new file mode 100755 index 0000000..2397ef7 --- /dev/null +++ b/bin/acme-scripts/gl @@ -0,0 +1,5 @@ +#!/bin/sh +# git-log, but piped through plumb so that it: +# 1. doesn't scroll to the end +# 2. has the proper "filename" so that plumbing SHA's works +git log "$@" | plumb -i -d edit -a "action=showdata filename=/$(pwd)/git-log" diff --git a/bin/acme-scripts/glo b/bin/acme-scripts/glo new file mode 100755 index 0000000..b93a408 --- /dev/null +++ b/bin/acme-scripts/glo @@ -0,0 +1,2 @@ +#!/bin/sh +exec gl --oneline diff --git a/bin/acme-scripts/gls b/bin/acme-scripts/gls new file mode 100755 index 0000000..133a8b1 --- /dev/null +++ b/bin/acme-scripts/gls @@ -0,0 +1,2 @@ +#!/bin/sh +exec gl --stat diff --git a/bin/acme-scripts/gs b/bin/acme-scripts/gs new file mode 100755 index 0000000..d1de923 --- /dev/null +++ b/bin/acme-scripts/gs @@ -0,0 +1,2 @@ +#!/bin/sh +exec git status "$@" diff --git a/bin/acme-scripts/i+ b/bin/acme-scripts/i+ new file mode 100755 index 0000000..8fc7768 --- /dev/null +++ b/bin/acme-scripts/i+ @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/^/ /' "$@" diff --git a/bin/acme-scripts/i- b/bin/acme-scripts/i- new file mode 100755 index 0000000..db0bf3c --- /dev/null +++ b/bin/acme-scripts/i- @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/^ //' diff --git a/bin/acme-scripts/jq b/bin/acme-scripts/jq new file mode 100755 index 0000000..2c26770 --- /dev/null +++ b/bin/acme-scripts/jq @@ -0,0 +1,3 @@ +#!/bin/sh +# monochrome jq +exec /usr/bin/jq -M "$@" diff --git a/bin/acme-scripts/nas b/bin/acme-scripts/nas new file mode 100755 index 0000000..41f2591 --- /dev/null +++ b/bin/acme-scripts/nas @@ -0,0 +1,14 @@ +#!/bin/sh +# nas -- new acme script +DIR=$(dirname "$(readlink -f "$0")") + +if [ -z "$1" ]; then + echo "usage: nas FILE" 1>&2 + exit 1 +fi + +file="$DIR/$1" + +touch "$file" +chmod +x "$file" +B "$file" \ No newline at end of file diff --git a/bin/gg b/bin/gg deleted file mode 100755 index 467a521..0000000 --- a/bin/gg +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# gg -- git grep with numbers. Not a git alias for use with acme(1) -# (which works best with commands with no spaces) -exec git grep -n "$@" diff --git a/lib/plumbing b/lib/plumbing new file mode 100644 index 0000000..64f7bf3 --- /dev/null +++ b/lib/plumbing @@ -0,0 +1,40 @@ +# plan9 plumbing rules +# +# currently in use in acme(1) on Linux via plan9port. +# +# see /usr/lib/plan9/plumb, plumb(7), and regexp(7) +# to update: cat $home/lib/plumbing | 9p write plumb/rules + +# urls go to web browser +type is text +data matches '(https?|file)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*' +plumb to web +plumb start chromium $0 + +# image files go to feh +type is text +data matches '[a-zA-Z0-9_\-./]+' +data matches '([a-zA-Z0-9_\-./]+)\.(jpe?g|JPE?G|gif|GIF|png|PNG)' +arg isfile $0 +plumb to image +plumb start feh $file + +# pdf files go to chromium +type is text +data matches '[a-zA-Z0-9_\-./]+' +data matches '([a-zA-Z0-9_\-./]+)\.(pdf|PDF)' +arg isfile $0 +plumb start chromium $file + +# man pages use system man (but searches plan9 too!) +type is text +data matches '([a-zA-Z¡-￿0-9_\-./]+)\(([1-8])\)' +plumb start rc -c '/usr/bin/man -m /usr/lib/plan9/man '$2' '$1' >[2=1] | nobs | plumb -i -d edit -a ''action=showdata filename=/man/'$1'('$2')''' + +# sha1's to git +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'''' + +editor = acme +include basic -- libgit2 1.1.1