有点上下文,这个问题是这个问题的后续:Bash remote autocompletion : change the 'starting' directory
无论如何,我正在编写我的自定义自动完成 bash 脚本:我希望自动完成能够像cd
那样工作,除了我想从特定目录中获取名称,不一定是当前目录。它工作得很好,除非文件名中有空格。
一个简单的例子。假设我从中获取名称的目录中有两个文件:a_file
和another file
(注意空格)。有时候是这样的:
my_command
TABTAB
a_file
file
another
演示文稿并不完美,但我的想法是提示我有 3 个选择,another file
分为another
和file
。所需的输出将是:
file_1
another file
。我还希望自动转义空格:
my_command ano
TAB
my_command another\ file
这是我的脚本的样子:
#!/bin/bash _get_file_list() { dir="/some/path/" cd $目录 查找 * -maxdepth 0 } _GetOptMyCommand() { 本地货币 完全=() cur=${COMP_WORDS[COMP_CWORD]} 案例“$cur”在 -*) COMPREPLY=( $( compgen -W "-h -l --help --list --" -- "$cur" ) );; *) COMPREPLY=( …