From e6f7f1b7b3d323f048392f89fc95e486b7a92d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marciniak?= <50745572+sunwire@users.noreply.github.com> Date: Sun, 5 Jun 2022 15:41:08 +0100 Subject: [PATCH] Add bash completion (#84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paweł Marciniak --- Makefile.am | 2 +- bash-completion/Makefile.am | 4 ++++ bash-completion/stenc | 40 +++++++++++++++++++++++++++++++++++++ configure.ac | 33 +++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 bash-completion/Makefile.am create mode 100644 bash-completion/stenc diff --git a/Makefile.am b/Makefile.am index 99b27b8..4a2c33b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = src man tests +SUBDIRS = src man tests bash-completion # EXTRA_DIST = buildconf diff --git a/bash-completion/Makefile.am b/bash-completion/Makefile.am new file mode 100644 index 0000000..2116a34 --- /dev/null +++ b/bash-completion/Makefile.am @@ -0,0 +1,4 @@ +if ENABLE_BASH_COMPLETION +bashcompletiondir = $(BASH_COMPLETION_DIR) +dist_bashcompletion_DATA = stenc +endif diff --git a/bash-completion/stenc b/bash-completion/stenc new file mode 100644 index 0000000..ff1c92a --- /dev/null +++ b/bash-completion/stenc @@ -0,0 +1,40 @@ +#stenc bash completion + +_stenc () { + local cur prev words cword + _init_completion || return + + COMPREPLY=() + + case $prev in + --version ) + return + ;; + -f ) + #list tape devices + for tape in /sys/class/scsi_tape/*; + do devs+="/dev/${tape##*/} "; + done; + COMPREPLY=($(compgen -W "$devs" -- "$cur")) + return + ;; + -e | --encrypt ) + COMPREPLY=($(compgen -W 'off on' -- "$cur")) + return + ;; + -d | --decrypt ) + COMPREPLY=($(compgen -W 'off on mixed' -- "$cur")) + return + ;; + -k | --keyfile ) + _filedir + return + ;; + esac + + if [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W '-f --file -e --encrypt -d --decrypt -k --key-file -a --algorithm --allow-raw-read --no-allow-raw-read --ckod -h --help --version' -- "$cur")) + return + fi +} +complete -F _stenc stenc diff --git a/configure.ac b/configure.ac index e1d7007..c1e2ed0 100644 --- a/configure.ac +++ b/configure.ac @@ -70,5 +70,36 @@ if test "${system}" = "FreeBSD"; then LIBS="${LIBS} -lcam" fi -AC_CONFIG_FILES([Makefile src/Makefile man/Makefile tests/Makefile]) +# BASH completion +AC_ARG_WITH([bash-completion-dir], + AS_HELP_STRING([--with-bash-completion-dir[=PATH]], + [Install the bash auto-completion script in this directory. @<:@default=yes@:>@]), + [], + [with_bash_completion_dir=yes]) + +if test "x$with_bash_completion_dir" = "xyes" +then + extra_args= + + if test "x$prefix" != "xNONE" + then + extra_args=$prefix + fi + +AC_MSG_NOTICE(extra_args is $extra_args) + + PKG_CHECK_MODULES([BASH_COMPLETON], [bash-completion >= 2.0], + [ + BASH_COMPLETION_DIR="$datadir/bash-completion/completions" + ]) +else + BASH_COMPLETION_DIR="$with_bash_completion_dir/" +fi + +AC_MSG_NOTICE(BASH_COMPLETION_DIR is $BASH_COMPLETION_DIR) + +AC_SUBST([BASH_COMPLETION_DIR]) +AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "xno"]) + +AC_CONFIG_FILES([Makefile src/Makefile man/Makefile tests/Makefile bash-completion/Makefile]) AC_OUTPUT