Notes

Home About Contact Archive
GitHub LinkedIn Twitter CoBUG.org

Tab completion in OpenBSD's ksh

How did I not know about this until now!?
Posted on Mon, 01 May 2017 18:18:00 MDT by Aaron Bieber
Tags: OpenBSD, ksh

OpenBSD’s ksh

..is the little shell that could. In ~20k lines of code, it has many of the same features as more popular shells like zsh and bash. Plus it has the added bonus of being pledge(2)’d!

One of the features OpenBSD’s ksh shares with its more popular friends is user definable completions! Something that sets it apart, however, is the simplicity of these completions. From the man page:

Custom completions may be configured by creating an array named
‘complete_command’, optionally suffixed with an argument number
to complete only for a single argument.

For example, here is a completion for vmctl(8) with expansion of defined VM names:

# vmctl
set -A complete_vmctl -- console load reload start stop reset status
set -A complete_vmctl_2 -- $(vmctl status | awk '!/NAME/{print $NF}')

Hats off to Nicholas Marriott nicm@ for implementing it and to brynet@ for pointing it out to me! I was close to switching to fish in an attempt to save my wrists.. but the ~180k lines of extra (yeah, on top of the 20k!) code in fish was kinda scaring me!

For anyone interested, here is a quick comparison of CLOC for a few popular shells:

Shell Version Total Lines (cloc)
ksh Mon May 1 07:17:54 UTC 2017 19680
zsh 5.3.1 127246
fish 2.5.0 207597
bash 4.4 351043

I understand LOC isn’t a good measure of quality, but it sure does mean you have a lot more reading to find that quality!

A full list of my completions can be found here!


Made by qbit. Subscribe via RSS / Atom | Generated using boring and these files.
PGP: 0x1F81112D62A9ADCE / 3586 3350 BFEA C101 DB1A 4AF0 1F81 112D 62A9 ADCE
proof.