xref: /linux/tools/testing/kunit/kunit-completion.sh (revision 23b0f90ba871f096474e1c27c3d14f455189d2d9)
1# SPDX-License-Identifier: GPL-2.0
2# bash completion support for KUnit
3
4_kunit_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5
6_kunit()
7{
8	local cur prev words cword
9	_init_completion || return
10
11	local script="${_kunit_dir}/kunit.py"
12
13	if [[ $cword -eq 1 && "$cur" != -* ]]; then
14		local cmds=$(${script} --list-cmds 2>/dev/null)
15		COMPREPLY=($(compgen -W "${cmds}" -- "$cur"))
16		return 0
17	fi
18
19	if [[ "$cur" == -* ]]; then
20		if [[ -n "${words[1]}" && "${words[1]}" != -* ]]; then
21			local opts=$(${script} ${words[1]} --list-opts 2>/dev/null)
22			COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
23			return 0
24		else
25			local opts=$(${script} --list-opts 2>/dev/null)
26			COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
27			return 0
28		fi
29	fi
30}
31
32complete -o default -F _kunit kunit.py
33complete -o default -F _kunit kunit
34complete -o default -F _kunit ./tools/testing/kunit/kunit.py
35