ACK: [PATCH] fwts: add bash command-line completion
Alex Hung
alex.hung at canonical.com
Tue Nov 7 09:02:13 UTC 2017
On 2017-11-04 11:00 PM, Anthony Wong wrote:
> So that we can use tab to complete options and arguments, making fwts
> more enjoyable to use.
>
> Signed-off-by: Anthony Wong <anthony.wong at canonical.com>
> ---
> Makefile.am | 2 +-
> configure.ac | 11 +++++
> debian/fwts.install | 1 +
> scripts/bash-completion/Makefile.am | 2 +
> scripts/bash-completion/fwts | 86 +++++++++++++++++++++++++++++++++++++
> 5 files changed, 101 insertions(+), 1 deletion(-)
> create mode 100644 scripts/bash-completion/Makefile.am
> create mode 100644 scripts/bash-completion/fwts
>
> diff --git a/Makefile.am b/Makefile.am
> index 278661c4..dcef6095 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -16,7 +16,7 @@
> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> #
>
> -SUBDIRS = src data src/utilities
> +SUBDIRS = src data src/utilities scripts/bash-completion
>
> ACLOCAL_AMFLAGS = -I m4
>
> diff --git a/configure.ac b/configure.ac
> index 2ef4f4f6..d7e0aee7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -106,5 +106,16 @@
> src/lib/src/Makefile
> src/utilities/Makefile
> data/Makefile
> + scripts/bash-completion/Makefile
> ])
> + AC_ARG_WITH([bashcompletiondir],
> + AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
> + [],
> + [AS_IF([`pkg-config --exists bash-completion`], [
> + with_bashcompletiondir=`pkg-config --variable=completionsdir bash-completion`
> + ], [
> + with_bashcompletiondir=${datadir}/bash-completion/completions
> + ])
> + ])
> + AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
> AC_OUTPUT
> diff --git a/debian/fwts.install b/debian/fwts.install
> index ec150f3a..cb342d57 100644
> --- a/debian/fwts.install
> +++ b/debian/fwts.install
> @@ -5,3 +5,4 @@ usr/bin/fwts usr/bin
> usr/share/man/man1/fwts.1 usr/share/man/man1
> scripts/fwts-collect usr/bin
> usr/share/man/man1/fwts-collect.1 usr/share/man/man1
> +usr/share/bash-completion/completions/fwts usr/share/bash-completion/completions
> diff --git a/scripts/bash-completion/Makefile.am b/scripts/bash-completion/Makefile.am
> new file mode 100644
> index 00000000..a8b6ec8a
> --- /dev/null
> +++ b/scripts/bash-completion/Makefile.am
> @@ -0,0 +1,2 @@
> +bashcompletiondir = @bashcompletiondir@
> +dist_bashcompletion_DATA = fwts
> diff --git a/scripts/bash-completion/fwts b/scripts/bash-completion/fwts
> new file mode 100644
> index 00000000..6cd0b25a
> --- /dev/null
> +++ b/scripts/bash-completion/fwts
> @@ -0,0 +1,86 @@
> +#!/bin/bash
> +#
> +# FWTS tab completion for bash.
> +#
> +# Copyright (C) 2017 Canonical
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License
> +# as published by the Free Software Foundation; either version 2
> +# of the License, or (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> +
> +_fwts()
> +{
> + local cur prev
> +
> + cur=${COMP_WORDS[COMP_CWORD]}
> + prev=${COMP_WORDS[COMP_CWORD-1]}
> +
> + case $prev in
> + '--arch')
> + COMPREPLY=( $(compgen -W "x86 x86_32 x86_64 ia64 arm64 aarch64" -- $cur) )
> + compopt -o nosort
> + return 0
> + ;;
> + '--dumpfile'|'-k'|'--klog'|'-J'|'--json-data-file'|'--lspci'|'-o'|'--olog'|'--s3-resume-hook'|'-r'|'--results-output')
> + _filedir
> + return 0
> + ;;
> + '-j'|'--json-data-path'|'-t'|'--table-path')
> + local IFS=$'\n'
> + compopt -o filenames
> + COMPREPLY=( $(compgen -d -- ${cur}) )
> + return 0
> + ;;
> + '--log-level')
> + COMPREPLY=( $(compgen -W "critical high medium low info all" -- $cur) )
> + compopt -o nosort
> + return 0
> + ;;
> + '--log-type')
> + COMPREPLY=( $(compgen -W "plaintext json xml" -- $cur) )
> + return 0
> + ;;
> + '--pm-method')
> + COMPREPLY=( $(compgen -W "logind pm-utils sysfs" -- $cur) )
> + return 0
> + ;;
> + '--log-filter'|'--log-format'|'-w'|'--log-width'|'-R'|'-rsdp'|\
> + '--s3-delay-delta'|'--s3-device-check-delay'|'--s3-max-delay'|'--s3-min-delay'|'--s3-multiple'|\
> + '--s3-quirks'|'--s3-resume-time'|'--s3-sleep-delay'|'--s3-suspend-time'|'--s3power-sleep-delay'|\
> + '--s4-delay-delta'|'--s4-device-check-delay'|'--s4-max-delay'|'--s4-min-delay'|'--s4-multiple'|'--s4-quirks'|'--s4-sleep-delay'|\
> + '-s'|'--skip-test'|'--uefi-get-var-multiple'|'--uefi-query-var-multiple'|'--uefi-set-var-multiple')
> + # argument required but no completions available
> + return 0
> + ;;
> + '-h'|'--help'|'-v'|'--version'|'-d'|'--dump'|'-s'|'--show-tests'|'--show-tests-full'|'--show-tests-categories'|'--log-fields')
> + # all other arguments are noop with these
> + return 0
> + ;;
> + esac
> +
> + local all_tests=`fwts --show-tests | sed '/.*:/d;/^$/d' | awk '{ print $1 }'`
> + local all_long_options=$( _parse_help "$1" --help )
> +
> + if [ -z "$cur" ]; then
> + COMPREPLY=( $( compgen -W "${all_tests}" -- "$cur" ) )
> + else
> + COMPREPLY=( $( compgen -W "${all_tests} ${all_long_options}" -- "$cur" ) )
> +
> + fi
> +
> + return 0
> +}
> +
> +
> +# load the completion
> +complete -F _fwts fwts
>
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list