diff --git a/completions/Makefile.am b/completions/Makefile.am index 8d5c92ccaca..fd5cf57601e 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -395,6 +395,7 @@ bashcomp_DATA = 2to3 \ sha256sum \ shellcheck \ sitecopy \ + slabtop \ _slackpkg \ slapt-get \ slapt-src \ diff --git a/completions/slabtop b/completions/slabtop new file mode 100644 index 00000000000..7ce8be0f2b6 --- /dev/null +++ b/completions/slabtop @@ -0,0 +1,31 @@ +# bash completion for slabtop -*- shell-script -*- + +_comp_cmd_slabtop() +{ + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + local noargopts='!(-*|*[ds]*)' + # shellcheck disable=SC2254 + case $prev in + --help | --version | --delay | -${noargopts}[hVd]) + return + ;; + --sort | -${noargopts}s) + _comp_compgen_split -- "$( + "$1" --help | command sed \ + -e '/^The following are valid sort criteria/,/^$/!d' \ + -ne 's/^[[:space:]]\(.\):.*/\1/p' + )" + return + ;; + esac + + if [[ $cur == -* ]]; then + _comp_compgen_help + return + fi +} && + complete -F _comp_cmd_slabtop slabtop + +# ex: filetype=sh diff --git a/test/t/Makefile.am b/test/t/Makefile.am index 5a599693d9d..f7a297489b9 100644 --- a/test/t/Makefile.am +++ b/test/t/Makefile.am @@ -560,6 +560,7 @@ EXTRA_DIST = \ test_shar.py \ test_shellcheck.py \ test_sitecopy.py \ + test_slabtop.py \ test_slackpkg.py \ test_slapt_get.py \ test_slapt_src.py \ diff --git a/test/t/test_slabtop.py b/test/t/test_slabtop.py new file mode 100644 index 00000000000..74c47598e9e --- /dev/null +++ b/test/t/test_slabtop.py @@ -0,0 +1,11 @@ +import pytest + + +class TestSlabtop: + @pytest.mark.complete("slabtop --", require_cmd=True) + def test_basic(self, completion): + assert completion + + @pytest.mark.complete("slabtop --sort ", require_cmd=True) + def test_sort_arg(self, completion): + assert completion diff --git a/test/test-cmd-list.txt b/test/test-cmd-list.txt index 5dda3e04b93..c16c9596766 100644 --- a/test/test-cmd-list.txt +++ b/test/test-cmd-list.txt @@ -343,6 +343,7 @@ sha512sum shar shellcheck sitecopy +slabtop slapt-get slapt-src smartctl