Skip to content

Commit

Permalink
chmod: Fix file completion after modes starting with a dash
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Dec 25, 2018
1 parent 3809d95 commit 75ec298
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions completions/chmod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ _chmod()

$split && return

if [[ $cur == -* ]]; then
# Adapted from coreutils 8.28 chmod man page
local modearg="-@(+(*([rwxXst])|[ugo])|+([0-7]))"

if [[ $cur == -* && $cur != $modearg ]]; then
local opts=$( _parse_help "$1" )
[[ $opts ]] || opts=$( _parse_usage "$1" )
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
Expand All @@ -26,7 +29,7 @@ _chmod()
fi

local args
_count_args
_count_args "" "" "$modearg"

case $args in
1) ;; # mode
Expand Down
8 changes: 8 additions & 0 deletions test/t/test_chmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ def test_2(self, completion):
@pytest.mark.complete("chmod -")
def test_3(self, completion):
assert completion.list

@pytest.mark.complete("chmod -x ")
def test_4(self, completion):
assert completion.list

@pytest.mark.complete("chmod -77 ")
def test_5(self, completion):
assert completion.list

0 comments on commit 75ec298

Please sign in to comment.