Skip to content

Commit 2d50f40

Browse files
Low-powerakinomyoga
authored andcommitted
feat: add new completion for chflags
1 parent 0543d1a commit 2d50f40

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bashcomp_DATA = 2to3 \
5151
check_db \
5252
check_perms \
5353
checksec \
54+
chflags \
5455
_chfn \
5556
chgrp \
5657
chkconfig \

completions/chflags

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# chflags(1) completion -*- shell-script -*-
2+
3+
[[ $OSTYPE == *@(bsd|darwin)* ]] || return 1
4+
5+
_comp_cmd_chflags()
6+
{
7+
local cur prev words cword comp_args
8+
_comp_initialize -- "$@" || return
9+
10+
if [[ $cur == -* ]]; then
11+
# Complete -options
12+
local w opts=""
13+
for w in "${words[@]}"; do
14+
[[ $w == -R ]] && opts="-H -L -P" && break
15+
done
16+
_comp_compgen -- -W '-f -h -v -x -R $opts'
17+
else
18+
local REPLY
19+
# The first argument is a list of flags; the rest are filedir.
20+
_comp_count_args
21+
if ((REPLY == 1)); then
22+
case "$OSTYPE" in
23+
*netbsd*)
24+
_comp_delimited , -W '
25+
arch opaque nodump sappnd schg uappnd uchg'
26+
;;
27+
*openbsd*)
28+
_comp_delimited , -W 'arch nodump sappnd schg uappnd uchg'
29+
;;
30+
*)
31+
_comp_delimited , -W '
32+
simmutable nosimmutable sappend nosappend archived
33+
noarchived sunlink nosunlink opaque noopaque nodump
34+
dump uimmutable nouimmutable uappend nouappend hidden
35+
nohidden uunlink nouunlink'
36+
;;
37+
esac
38+
else
39+
_comp_compgen_filedir
40+
fi
41+
fi
42+
} &&
43+
complete -F _comp_cmd_chflags chflags
44+
45+
# ex: filetype=sh

test/t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ EXTRA_DIST = \
7373
test_check_db.py \
7474
test_check_perms.py \
7575
test_checksec.py \
76+
test_chflags.py \
7677
test_chfn.py \
7778
test_chgrp.py \
7879
test_chkconfig.py \

test/t/test_chflags.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
4+
class TestChflags:
5+
@pytest.mark.complete("chflags no")
6+
def test_basic(self, completion):
7+
assert completion
8+
9+
@pytest.mark.complete("chflags -")
10+
def test_basic(self, completion):
11+
assert completion and "-P" not in completion
12+
13+
@pytest.mark.complete("chflags -R -")
14+
def test_basic(self, completion):
15+
assert "-P" in completion
16+
17+
@pytest.mark.complete("chflags -v sappend ")
18+
def test_basic(self, completion):
19+
assert completion
20+

0 commit comments

Comments
 (0)