Joe macros FTW

I’ve been using Linux for more years than I care to admit, but it’s been long enough that my choice of text editor was informed by what was available for the first Linux distribution I tried that:

  1. Had a gentler learning curve than vi/vim
  2. Had a binary package that fit on a single floppy (so no emacs)

Thus began my multi-decade love affair with Joe.

Fast forward to the beginning of my time editing RPM spec files; first for myself, then for Fedora Extras, then for Fedora at large, EPEL, employers, etc. One of the most common errors I see are bogus dates in changelogs. That, and people who manage to misspell their own names and/or email addresses. I’ve done it. If you’ve made any reasonable number of spec edits, you’ve almost certainly done it. So we’re careful. We check the date, the day of the week, and do our best. We copy/paste/edit when we can.

I shudder to think of the time I’ve lost taking care to get my changelog entries right.

This morning, I finally worked out a time-saver, and I think some of you might find it useful.

vi, emacs, and presumably other editors, allow you to insert the output of a script into the current buffer at the location of the cursor. Joe will only append to the end of the file, which is silly, and if someone knows how to insert at the current location, please let me know.

But at any rate, the following bash script:

#!/bin/bash
DATE=`date +%a\ %b\ %d\ %Y`
NAME=`git config --get user.name`
EMAIL=`git config --get user.email`
echo "* $DATE $NAME <$EMAIL>"

will output a usable string as follows:

* Wed Jul 25 2018 Your Name <youremail@example.com>

For joe, you need to pipe this to a file and then create a macro like:

Ctrl+K [ (choose a number
insf,"~/your/file",rtn
Ctrl+K ]

And then run it with:

Crtl+k <number>

And you’re set!

Advertisements