Search code examples
fish

Completion for filenames without root, only extension (hidden files)


I'm trying to write a completion for a command that takes filenames that have no root/base part, only extension (such as "foo/.ext"). Hidden files. (Specifically, ".envrc" for direnv.)

There are several examples to follow in fish's installation that use __fish_complete_suffix for files that have a root and extension, such as fish itself:

complete -c fish -k -x -a "(__fish_complete_suffix .fish)"

The same thing for hidden files, files without a root, doesn't work.

# completions/foo.fish
complete -c foo -k -x -a "(__fish_complete_suffix .bar)"

# functions/foo.fish
function foo
    echo $argv
end

> mkdir -p a/b; touch a/1.bar a/2.bar a/.bar
> foo a/<TAB>
a/1.bar  a/2.bar  a/b/

Is there a way to accomplish this with this or some other function(s)?


Solution

  • fish doesn't add hidden files to the list of completions unless the token being completed already starts with a '.'.

    You should be able to write a custom completion that does what you want, but unfortunately a long-standing bug makes that impossible.