鱼壳完井保持顺序



如何使用--keep-order

我的函数是这样的:

function filterfile -a file -a word
grep -i $word $file
grep -iv $word $file | sponge $file
end

和我的完成是这样的:

complete -k -c filterfile --require-parameter --no-files -a "(cat (commandline -opc)[2])"
complete -k -c filterfile --require-parameter

在文档后面"使用-k的多个完整调用导致后面的参数首先显示",但是当我为文件路径按tab时,什么也没有发生

如果我理解正确的话,你有一个函数filterfile,它需要两个参数,一个文件名和一个要在文件中搜索的单词。您希望第一个参数以制表符完成文件名,第二个参数以制表符完成文件中第一个参数给出的单词。

您可以通过使用--condition选项(简称-n)到complete来做到这一点,这里有文档说明。在这里,我们使用辅助函数__fish_is_first_arg来控制何时完成:

# Complete first argument as files.
complete -c filterfile --condition __fish_is_first_arg --force-files
# Complete remaining arguments as words in the file from the first argument.
complete --keep-order -c filterfile --condition 'not __fish_is_first_arg' --no-files -a '(cat (__fish_first_token))'

现在第一个参数应该以文件的形式完成,第二个+参数应该以第一个参数命名的文件中的单词完成。

(注意,__fish_is_first_arg是一个普通的fish函数,随fish一起提供)

为了回答您最初的问题,--keep-order选项按照打印的顺序提供补全,而不是排序。与--keep-order:

> cat words.txt
sweater
handy
scarecrow
card
geese
> filterfile words.txt <tab>
sweater  handy  scarecrow  card  geese

补全以原来的顺序出现。没有:

> filterfile words.txt <tab>
card  geese  handy  scarecrow  sweater

补全按字母顺序排序。

最新更新