From 2d50f40659366aafc80b800ef21b8b9eabde7f23 Mon Sep 17 00:00:00 2001 From: WHR Date: Tue, 30 Jan 2024 22:36:57 +0800 Subject: [PATCH 1/4] feat: add new completion for `chflags` --- completions/Makefile.am | 1 + completions/chflags | 45 +++++++++++++++++++++++++++++++++++++++++ test/t/Makefile.am | 1 + test/t/test_chflags.py | 20 ++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 completions/chflags create mode 100644 test/t/test_chflags.py diff --git a/completions/Makefile.am b/completions/Makefile.am index 219ea10dab6..ceced249b8d 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -51,6 +51,7 @@ bashcomp_DATA = 2to3 \ check_db \ check_perms \ checksec \ + chflags \ _chfn \ chgrp \ chkconfig \ diff --git a/completions/chflags b/completions/chflags new file mode 100644 index 00000000000..1c6ad1d2bc6 --- /dev/null +++ b/completions/chflags @@ -0,0 +1,45 @@ +# chflags(1) completion -*- shell-script -*- + +[[ $OSTYPE == *@(bsd|darwin)* ]] || return 1 + +_comp_cmd_chflags() +{ + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + if [[ $cur == -* ]]; then + # Complete -options + local w opts="" + for w in "${words[@]}"; do + [[ $w == -R ]] && opts="-H -L -P" && break + done + _comp_compgen -- -W '-f -h -v -x -R $opts' + else + local REPLY + # The first argument is a list of flags; the rest are filedir. + _comp_count_args + if ((REPLY == 1)); then + case "$OSTYPE" in + *netbsd*) + _comp_delimited , -W ' + arch opaque nodump sappnd schg uappnd uchg' + ;; + *openbsd*) + _comp_delimited , -W 'arch nodump sappnd schg uappnd uchg' + ;; + *) + _comp_delimited , -W ' + simmutable nosimmutable sappend nosappend archived + noarchived sunlink nosunlink opaque noopaque nodump + dump uimmutable nouimmutable uappend nouappend hidden + nohidden uunlink nouunlink' + ;; + esac + else + _comp_compgen_filedir + fi + fi +} && + complete -F _comp_cmd_chflags chflags + +# ex: filetype=sh diff --git a/test/t/Makefile.am b/test/t/Makefile.am index 5a599693d9d..7a2a0671435 100644 --- a/test/t/Makefile.am +++ b/test/t/Makefile.am @@ -73,6 +73,7 @@ EXTRA_DIST = \ test_check_db.py \ test_check_perms.py \ test_checksec.py \ + test_chflags.py \ test_chfn.py \ test_chgrp.py \ test_chkconfig.py \ diff --git a/test/t/test_chflags.py b/test/t/test_chflags.py new file mode 100644 index 00000000000..28d5af49de5 --- /dev/null +++ b/test/t/test_chflags.py @@ -0,0 +1,20 @@ +import pytest + + +class TestChflags: + @pytest.mark.complete("chflags no") + def test_basic(self, completion): + assert completion + + @pytest.mark.complete("chflags -") + def test_basic(self, completion): + assert completion and "-P" not in completion + + @pytest.mark.complete("chflags -R -") + def test_basic(self, completion): + assert "-P" in completion + + @pytest.mark.complete("chflags -v sappend ") + def test_basic(self, completion): + assert completion + From 44f29dae2c11f6e228d7e947e9aa0e6d9c1fb106 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 13 May 2024 20:06:34 +0900 Subject: [PATCH 2/4] feat(chflags): complete "-x" only for FreeBSD --- completions/chflags | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completions/chflags b/completions/chflags index 1c6ad1d2bc6..e7350420575 100644 --- a/completions/chflags +++ b/completions/chflags @@ -13,7 +13,8 @@ _comp_cmd_chflags() for w in "${words[@]}"; do [[ $w == -R ]] && opts="-H -L -P" && break done - _comp_compgen -- -W '-f -h -v -x -R $opts' + [[ $OSTYPE == *freebsd* ]] && opts="$opts -x" + _comp_compgen -- -W '-f -h -v -R $opts' else local REPLY # The first argument is a list of flags; the rest are filedir. From 8b653272b4d37a74e64d7140444a3540d503201e Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 13 May 2024 20:08:13 +0900 Subject: [PATCH 3/4] docs(chflags): add references --- completions/chflags | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/completions/chflags b/completions/chflags index e7350420575..9bac75c9dd9 100644 --- a/completions/chflags +++ b/completions/chflags @@ -2,6 +2,12 @@ [[ $OSTYPE == *@(bsd|darwin)* ]] || return 1 +# References +# +# [1] FreeBSD - https://man.freebsd.org/cgi/man.cgi?chflags(1) +# [2] NetBSD - https://man.netbsd.org/NetBSD-9.0/chflags.1 +# [3] OpenBSD - https://man.openbsd.org/chflags.1 + _comp_cmd_chflags() { local cur prev words cword comp_args From a50f20119df3e4aee7fedd717dfc520851d698da Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 13 May 2024 20:45:34 +0900 Subject: [PATCH 4/4] test(chflags): fix test names --- test/t/test_chflags.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/t/test_chflags.py b/test/t/test_chflags.py index 28d5af49de5..047a9aadefb 100644 --- a/test/t/test_chflags.py +++ b/test/t/test_chflags.py @@ -7,14 +7,13 @@ def test_basic(self, completion): assert completion @pytest.mark.complete("chflags -") - def test_basic(self, completion): + def test_options(self, completion): assert completion and "-P" not in completion @pytest.mark.complete("chflags -R -") - def test_basic(self, completion): + def test_options_after_R(self, completion): assert "-P" in completion @pytest.mark.complete("chflags -v sappend ") - def test_basic(self, completion): + def test_first_word(self, completion): assert completion -