Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

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)?

question from:https://stackoverflow.com/questions/65948055/completion-for-filenames-without-root-only-extension-hidden-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...