Skip to content

Commit

Permalink
Support files in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
kx-chen committed Jul 8, 2020
1 parent 4a1eb21 commit e811891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
IFS=',' read type value <<< "$completion"
if [[ $type == 'path' ]]; then
COMPREPLY=($(compgen -d -S / -- $value ))
elif [[ $type == 'file' ]]; then
IFS=$'\n'
FILES=( $(compgen -W "$(ls -p | grep -v /)" -- $value))
IFS=' '
COMPREPLY=( "${FILES[@]// /\\ }" )
elif [[ $type == 'none' ]]; then
COMPREPLY+=("$value ")
fi
Expand Down
3 changes: 3 additions & 0 deletions src/click/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ def convert(self, value, param, ctx):
ctx,
)

def shell_complete(self, ctx, all_args, incomplete):
return [["file", incomplete, None]]


class Path(ParamType):
"""The path type is similar to the :class:`File` type but it performs
Expand Down

0 comments on commit e811891

Please sign in to comment.