Add completion for image filenames at command line

Sadly could not get it to work with the shell
This commit is contained in:
Kovid Goyal
2020-02-01 12:33:11 +05:30
parent 2f9dabd344
commit 226488717a
3 changed files with 27 additions and 4 deletions

View File

@@ -266,7 +266,11 @@ def complete_remote_command(ans, cmd_name, words, new_word):
aliases, alias_map = options_for_cmd(cmd_name)
if not alias_map:
return
complete_alias_map(ans, words, new_word, alias_map)
args_completion = cmap[cmd_name].args_completion
args_completer = None
if 'files' in args_completion:
args_completer = remote_files_completer(args_completion['files'])
complete_alias_map(ans, words, new_word, alias_map, complete_args=args_completer)
def path_completion(prefix=''):
@@ -326,6 +330,22 @@ def complete_icat_args(ans, opt, prefix):
complete_files_and_dirs(ans, prefix, 'Images', icat_file_predicate)
def remote_files_completer(spec):
name, matchers = spec
def complete_files_map(ans, opt, prefix):
def predicate(filename):
for m in matchers:
if isinstance(m, str):
from fnmatch import fnmatch
return fnmatch(filename, m)
if opt is None:
complete_files_and_dirs(ans, prefix, name, predicate)
return complete_files_map
def config_file_predicate(filename):
return filename.endswith('.conf')