Skip to content

Commit 75ec298

Browse files
committed
chmod: Fix file completion after modes starting with a dash
1 parent 3809d95 commit 75ec298

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

completions/chmod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ _chmod()
1717

1818
$split && return
1919

20-
if [[ $cur == -* ]]; then
20+
# Adapted from coreutils 8.28 chmod man page
21+
local modearg="-@(+(*([rwxXst])|[ugo])|+([0-7]))"
22+
23+
if [[ $cur == -* && $cur != $modearg ]]; then
2124
local opts=$( _parse_help "$1" )
2225
[[ $opts ]] || opts=$( _parse_usage "$1" )
2326
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
@@ -26,7 +29,7 @@ _chmod()
2629
fi
2730

2831
local args
29-
_count_args
32+
_count_args "" "" "$modearg"
3033

3134
case $args in
3235
1) ;; # mode

test/t/test_chmod.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ def test_2(self, completion):
1515
@pytest.mark.complete("chmod -")
1616
def test_3(self, completion):
1717
assert completion.list
18+
19+
@pytest.mark.complete("chmod -x ")
20+
def test_4(self, completion):
21+
assert completion.list
22+
23+
@pytest.mark.complete("chmod -77 ")
24+
def test_5(self, completion):
25+
assert completion.list

0 commit comments

Comments
 (0)