小编Pie*_*nne的帖子

自定义自动完成:处理文件名中的空格

有点上下文,这个问题是这个问题的后续:Bash remote autocompletion : change the 'starting' directory

无论如何,我正在编写我的自定义自动完成 bash 脚本:我希望自动完成能够像cd那样工作,除了我想从特定目录中获取名称,不一定是当前目录。它工作得很好,除非文件名中有空格。

一个简单的例子。假设我从中获取名称的目录中有两个文件:a_fileanother file(注意空格)。有时候是这样的:

my_commandTABTAB
a_file file another

演示文稿并不完美,但我的想法是提示我有 3 个选择,another file分为anotherfile。所需的输出将是: file_1 another file。我还希望自动转义空格:

my_command anoTAB
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=( …

bash autocomplete

8
推荐指数
1
解决办法
3093
查看次数

标签 统计

autocomplete ×1

bash ×1