[PATCH i-g-t v1 1/2] RFC /scripts/bash-autocomplete: Create bash autocompletion scripts for tests
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Wed Jul 16 06:10:05 UTC 2025
On Mon, Jul 14, 2025 at 12:01:29PM +0000, Jan Sokolowski wrote:
> Add installation and uninstallation scripts for bash autocompletion
> for tests.
>
> Signed-off-by: Jan Sokolowski <jan.sokolowski at intel.com>
> Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Kamil Konieczny <kamil.konieczny at linux.intel.com>
> Cc: Katarzyna Piecielska <katarzyna.piecielska at intel.com>
> Cc: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> Cc: Ashutosh Dixit <ashutosh.dixit at intel.com>
> ---
> .../install_completions.sh | 47 +++++++++++++++++++
> .../uninstall_completions.sh | 9 ++++
> 2 files changed, 56 insertions(+)
> create mode 100755 scripts/bash_autocompletion/install_completions.sh
> create mode 100755 scripts/bash_autocompletion/uninstall_completions.sh
>
> diff --git a/scripts/bash_autocompletion/install_completions.sh b/scripts/bash_autocompletion/install_completions.sh
> new file mode 100755
> index 000000000..40cc87403
> --- /dev/null
> +++ b/scripts/bash_autocompletion/install_completions.sh
> @@ -0,0 +1,47 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: MIT
> +# Copyright © 2025 Intel Corporation
> +# Author: Jan Sokolowski <jan.sokolowski at intel.com>
> +
> +__generate_completion() {
> +
> +cat <<EOF > $1
> +_$1()
> +{
> + local cur prev words cword
> + _init_completion || return
> +
> + case \$prev in
> + --run-subtest | --dynamic-subtest)
> + local IFS=$'\n\b'
> + LIST_OF_TESTS="echo -e \`/usr/local/libexec/igt-gpu-tools/$1 --list-subtest\`"
> + COMPREPLY=(\$(compgen -W "\$LIST_OF_TESTS" -- "\$cur"))
> + return
> + ;;
> + --device)
> + COMPREPLY=(\$(compgen -o nospace -W "sys: pci: sriov: drm:" -- "\$cur"))
> + ;;
> + esac
> +
> + if [[ \$cur == -* ]]; then
> + COMPREPLY=(\$(compgen -W '\$(_parse_help "/usr/local/libexec/igt-gpu-tools/$1")' -- "\$cur"))
> + fi
> +
> +} &&
> +complete -F _$1 $1
> +EOF
I wondered a bit about this and I think the best would be to provide
two autocompletions. First for binaries installed, but you have to
honour meson 'prefix', instead of hardcoding /usr/local/*.
Second, more useful for me which would produce "local" autocompletions
(I mean for ./testname). It might be installed to ~/.bash_completion.d/igt
or ~/.bash_completion.igt (or wherever in my home simply sourced from
~/.bashrc. Local ./testname autocompletion is more useful when you
develop the test (I execute them in build dir without installing).
At the moment I would guard both under 'disabled' flag.
> +
> +cp $1 /usr/share/bash-completion/completions/
> +
> +}
> +
> +mkdir /tmp/igt-gpu-tools-bash-completion-installer
mktemp?
> +cd /tmp/igt-gpu-tools-bash-completion-installer
> +
> +for TEST in `find /usr/local/libexec/igt-gpu-tools -type f | grep -v intel-ci-tests | rev | cut -d'/' -f1 | rev`;
I think better would be to use igt_runner -L to produce list of tests.
Unfortunately it depends on -Drunner=enabled flag. I think instead find
you proposed it would be to use:
$ find build -type f -executable
--
Zbigniew
> +do
> +__generate_completion $TEST
> +done
> +
> +cd -
> +rm -rf /tmp/igt-gpu-tools-bash-completion-installer
> diff --git a/scripts/bash_autocompletion/uninstall_completions.sh b/scripts/bash_autocompletion/uninstall_completions.sh
> new file mode 100755
> index 000000000..26345d6e2
> --- /dev/null
> +++ b/scripts/bash_autocompletion/uninstall_completions.sh
> @@ -0,0 +1,9 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: MIT
> +# Copyright © 2025 Intel Corporation
> +# Author: Jan Sokolowski <jan.sokolowski at intel.com>
> +
> +for TEST in `find /usr/local/libexec/igt-gpu-tools -type f | grep -v intel-ci-tests | rev | cut -d'/' -f1 | rev`;
> +do
> +rm /usr/share/bash-completion/completions/$TEST
> +done
> --
> 2.34.1
>
More information about the igt-dev
mailing list