How do I use --keep-order ?
My function looks like this:
function filterfile -a file -a word
grep -i $word $file
grep -iv $word $file | sponge $file
end
and my completions look like this:
complete -k -c filterfile --require-parameter --no-files -a "(cat (commandline -opc)[2])"
complete -k -c filterfile --require-parameter
Following the documentation "Multiple complete calls with -k result in arguments of the later ones displayed first", but when I press tab for a file path nothing happens
If I understand correctly, you have a function
filterfilewhich takes two arguments, a filename and a word to search for in the file. You would like the first argument to tab-complete as file names, and the second argument to tab-complete as words given in the file from the first argument.You can do this by using the
--conditionoption (short-n) tocomplete, documented here. Here we use the helper function__fish_is_first_argto control when our completions run:Now the first argument should tab-complete as files, and the second+ arguments should tab-complete as words found in the file named by the first argument.
(Note that
__fish_is_first_argis an ordinary fish function that ships with fish.)To answer your original question, the
--keep-orderoption offers completions in the order they are printed, instead of sorting. With--keep-order:The completions appear in their original order. Without:
the completions are sorted alphabetically.