From b7db022bedc536b72a5280b31e2534212e1f852d Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Thu, 2 Feb 2017 18:23:28 +0100 Subject: [PATCH] Add bash completion --- bash_completion | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bash_completion diff --git a/bash_completion b/bash_completion new file mode 100644 index 0000000..3284b5e --- /dev/null +++ b/bash_completion @@ -0,0 +1,28 @@ +# bkctld(8) completion +# +# Copyright (c) 2017 Victor Laborie +# + +function _bkctld() +{ + local cur prev commands jails keys + + cur=${COMP_WORDS[COMP_CWORD]}; + prev=${COMP_WORDS[COMP_CWORD-1]}; + commands="init update remove start stop reload restart sync status key port ip inc rm" + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=($(compgen -W '${commands}' -- ${cur})) + elif [ $COMP_CWORD -eq 2 ]; then + [ -f /etc/default/bkctld ] && source /etc/default/bkctld + [ -z "${JAILDIR}" ] && JAILDIR='/backup/jails' + jails=$(ls "${JAILDIR}") + COMPREPLY=($(compgen -W "${jails}" -- ${cur})) + elif [ $COMP_CWORD -eq 3 ]; then + keys=$(ls *.pub) + COMPREPLY=($(compgen -W "${keys}" -- ${cur})) + fi + + return 0 +} && +complete -F _bkctld bkctld