2017-08-24 64 views
1

我有一个脚本,需要文件中像参数(多部分参数),我取的可能值,并把它们放在一个数组称为raw,然后使用岩组完成不区分大小写_multi_parts功能

_multi_parts/"(${raw[@]})" 

自动完成。问题是这是区分大小写的,我怎样才能让它输入mycommand get fo并按Tab它会自动完成到mycommand get Foo/如果Foo是原始的东西之一。

全面完成是在这里以供参考:

Foo/Bar/x 
Foo/Bar/y 
Derp/z 
Placeholder/z 

回答

0

好吧,我想通了:

_mycommand() { 
    local curcontext="$curcontext" state line 

    _arguments "1: :->command" "*: :->label" 

    case $state in 
    command) 
    _arguments "1: :(add get ls rm)" 
    ;; 
    *) 
    case $words[2] in 
     add|get|ls|rm) 
     if [ -f ~/.pts ]; then 
      IFS=$'\n' read -d '' -r raw <<< "$(mycommand ls)" 
      _multi_parts/"(${raw[@]})" 
     fi 
     ;; 
     *) 
     _files 
     ;; 
    esac 
    esac 
} 

_mycommand "[email protected]" 

mycommand ls输出,如像下面的名字路径

更改线路

IFS=$'\n' read -d '' -r raw <<< "$(mycommand ls)" 
_multi_parts/"(${raw[@]})" 

IFS=$'\n' raw=($(mycommand ls)) 
_multi_parts -M "m:{[:lower:][:upper:]}={[:upper:][:lower:]}"/raw