2017-08-24 65 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