Command line completion in bash for DSEE and ZFS
I’m working on an environment for a customer where we are using Directory Server Enterprise Edition (DSEE) and ZFS. On the DSEE side, my co-worker Mitch and I were inspired by Ludovic’s post a while back about setting up command line completion for dsconf and dpconf. One small item Mitch noticed was that in the original examples, if you had a command name that didn’t contain a hypen (like dsconf import), it wouldn’t be completed (but command like dsconf get-server-prop would be).
Here is what Mitch came up with:
for cmd in dsconf dsadm dpconf dpadm; do
complete -W "`$cmd --help | \
perl -lane 'print $F[0] if \
(/^The accepted values for SUBCMD/ .. \
/^The accepted values for GLOBAL_OPTS/ \
and not /^The /)'`" $cmd
done
For ZFS, check out this script on Big Admin by Mark Musante.
Mitch did a small update to the script which made the list of sub-commands on the fly to account for additions. Mitch’s updated version is available here.