Skip to content

Commit

Permalink
find: fix -exec etc argument and its completion
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Apr 28, 2020
1 parent 85f3c73 commit 3e849c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions completions/find
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ _find()
local cur prev words cword
_init_completion || return

local i
for i in ${!words[*]}; do
if [[ ${words[i]} == -@(exec|ok)?(dir) ]]; then
_command_offset $((i+1))
return
fi
done

case $prev in
-maxdepth|-mindepth)
COMPREPLY=( $(compgen -W '{0..9}' -- "$cur") )
Expand Down Expand Up @@ -43,12 +51,6 @@ _find()
COMPREPLY=( $(compgen -u -- "$cur") )
return
;;
-exec|-execdir|-ok|-okdir)
words=(words[0] "$cur")
cword=1
_command
return
;;
-[acm]min|-[acm]time|-inum|-path|-ipath|-regex|-iregex|-links|-perm|\
-size|-used|-printf|-context)
# do nothing, just wait for a parameter to be given
Expand Down
10 changes: 10 additions & 0 deletions test/t/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ def test_5(self, completion):
@pytest.mark.complete("find -gid ")
def test_6(self, completion):
assert not [x for x in completion if not x.isdigit()]

@pytest.mark.complete("find -exec shared/bin/ar")
def test_exec(self, completion):
assert completion == "shared/bin/arp"

# sh +: something that produces completions also when command is not
# available, and the chosen completion is not one of find's
@pytest.mark.complete("find /some/where -exec sh +")
def test_exec_args(self, completion):
assert "+o" in completion

0 comments on commit 3e849c2

Please sign in to comment.