pacak / bpaf

Command line parser with applicative interface
336 stars 17 forks source link

`ShellComp::File` not working as expected on bash #371

Closed ozwaldorf closed 4 weeks ago

ozwaldorf commented 1 month ago

Installing completions for lutgen fe4450 which uses the file mask to eliminate non images:

*.avif|*.bmp|*.dds|*.exr|*.ff|*.gif|*.hdr|*.ico|*.jpg|*.jpeg|*.png|*.pnm|*.qoi|*.tga|*.tiff|*.webp

fails to work as expected on bash (hitting tab after some): image

compared to the correct suggestion by zsh: image


If needed, I can add a standalone example to reproduce the issue

pacak commented 1 month ago

I've seen your code, will try to reproduce it myself. Let's see what I can do about bash not cooperating :)

ozwaldorf commented 1 month ago

I was able to use !*.@(png|jpg|...) which still worked in zsh, but bash would show the current directories files and seemed to ignore what was typed. At least a little closer to expected behavior, but still not quite

ozwaldorf commented 1 month ago

Doing some more digging, even just using ShellComp::File { mask: None } ignores whatever prefix the user typed as well, and only suggests things in the current directory

bash only showing current dir: image

vs zsh working as expected: image

pacak commented 1 month ago

Hopefully will have a chance to look at it today. I have a general idea of what is going wrong, just need to look up the docs and change it to generate correctly escaped stuff.

pacak commented 1 month ago

after some experiments managed to produce this manually and it seem to work. Looks like key part for _filedir is having first two lines - local and initialization. So emitting those in addition to _filedir for bash should do the trick. Will try to write some of that tomorrow-ish.

_de()
{
   local cur prev words cword
   _init_completion || return
  _filedir '@(md|toml)'
}
complete -F _de de

_dr()
{
   local cur prev words cword
   _init_completion || return
  _filedir md
}
complete -F _dr dr

_dw()
{
   local cur prev words cword
   _init_completion || return
  _filedir
}
complete -F _dw dw
pacak commented 4 weeks ago

(I have something that works locally, will try to push a branch today)