Skip to content

complete --force-files does not work without options #7920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rouge8 opened this issue Apr 10, 2021 · 6 comments
Closed

complete --force-files does not work without options #7920

rouge8 opened this issue Apr 10, 2021 · 6 comments
Labels
bug Something that's not working as intended
Milestone

Comments

@rouge8
Copy link
Contributor

rouge8 commented Apr 10, 2021

fish version: 3.2.2

I'm trying to write completions for magic-wormhole and I'm struggling to complete paths outside of the current directory using __fish_complete_path with this completion file:

complete -e -c wormhole
complete --no-files -c wormhole

complete -c wormhole -l help
complete -c wormhole -l version -n "__fish_no_arguments"

complete -c wormhole -n __fish_use_subcommand -a receive -d "Receive a text message, file, or directory (from 'wormhole send')"

complete -c wormhole -n __fish_use_subcommand -a send -d "Send a text message, file, or directory"
complete -c wormhole -n "__fish_seen_subcommand_from send" -r -a "(__fish_complete_path)"

# This isn't a real option to wormhole but demonstrates the inconsistency
complete -c wormhole -l send -r -a "(__fish_complete_path)"
  • If I type, wormhole send <tab> it starts completing files in the current directory, as expected.
  • If I type wormhole send ~/<tab>, it doesn't complete anything, but I would expect it to complete the contents of my home directory
  • If I type wormhole --send ~/<tab>, it starts completing the contents of my home directory

Is there a way to get wormhole send ~/<tab> to complete the contents of my home directory? I'm also very confused why -a "(__fish_complete_path)" is behaving differently with a long option vs a subcommand.

@faho
Copy link
Member

faho commented Apr 10, 2021

__fish_complete_path completes directories. That is what it does - the brunt of it is command ls -dp, and the -d only lists directories.

What you want is to reenable files, like

complete -c wormhole -n "__fish_seen_subcommand_from send" -r -F

@faho faho added the question label Apr 10, 2021
@rouge8
Copy link
Contributor Author

rouge8 commented Apr 10, 2021

__fish_complete_path completes directories

This doesn't seem right, I see it returning directories and files:

__fish_complete_path ~/forks/fish-shell/
/Users/andy/forks/fish-shell/BSDmakefile	
/Users/andy/forks/fish-shell/CHANGELOG.rst	
/Users/andy/forks/fish-shell/CMakeLists.txt	
/Users/andy/forks/fish-shell/CODE_OF_CONDUCT.md	
/Users/andy/forks/fish-shell/CONTRIBUTING.rst	
/Users/andy/forks/fish-shell/COPYING	
/Users/andy/forks/fish-shell/Dockerfile	
/Users/andy/forks/fish-shell/GNUmakefile	
/Users/andy/forks/fish-shell/README.rst	
/Users/andy/forks/fish-shell/benchmarks/	
/Users/andy/forks/fish-shell/build/	
/Users/andy/forks/fish-shell/build,/	
/Users/andy/forks/fish-shell/build_tools/	
/Users/andy/forks/fish-shell/cmake/	
/Users/andy/forks/fish-shell/config_cmake.h.in	
/Users/andy/forks/fish-shell/debian/	
/Users/andy/forks/fish-shell/doc_src/	
/Users/andy/forks/fish-shell/docker/	
/Users/andy/forks/fish-shell/etc/	
/Users/andy/forks/fish-shell/fish.desktop	
/Users/andy/forks/fish-shell/fish.pc.in	
/Users/andy/forks/fish-shell/fish.png	
/Users/andy/forks/fish-shell/fish.spec.in	
/Users/andy/forks/fish-shell/osx/	
/Users/andy/forks/fish-shell/pcre2/	
/Users/andy/forks/fish-shell/po/	
/Users/andy/forks/fish-shell/share/	
/Users/andy/forks/fish-shell/src/	
/Users/andy/forks/fish-shell/tests/	

What you want is to reenable files, like

complete -c wormhole -n "__fish_seen_subcommand_from send" -r -F

With this, wormhole send <tab> doesn't complete anything at all. 😕

@faho
Copy link
Member

faho commented Apr 10, 2021

Oh, sorry, no, I misunderstood ls man page. What it means is that, for directories given as arguments it won't descend.

So ls ~/ will list the contents of your HOME, ls -d ~/ will print $HOME.

What __fish_complete_path does is complete its first argument one level. So you'll have to do -a '(__fish_complete_path (commandline -ct))'

This is an awkward interface, but it's also unnecessary given that -F exists.

Unfortunately that has a bug and only works with options (so if -s or -l or -o) is given. Fix incoming.

@rouge8
Copy link
Contributor Author

rouge8 commented Apr 10, 2021

it's also unnecessary given that -F exists.

Unfortunately that has a bug and only works with options (so if -s or -l or -o) is given. Fix incoming.

Ah thanks that would explain that! I'm still confused by the behavior of __fish_complete_path with a subcommand vs an option though.

What __fish_complete_path does is complete its first argument one level. So you'll have to do -a '(__fish_complete_path (commandline -ct))'

This still doesn't complete anything for wormhole send ~/<tab>, but does for wormhole --send ~/<tab>:

complete -e -c wormhole
complete --no-files -c wormhole

complete -c wormhole -n __fish_use_subcommand -a send -d "Send a text message, file, or directory"
complete -c wormhole -n "__fish_seen_subcommand_from send" -r -a '(__fish_complete_path (commandline -ct))'

# This isn't a real option to wormhole but demonstrates the inconsistency
complete -c wormhole -l send -r -a '(__fish_complete_path (commandline -ct))'

e.g.:

complete -C 'wormhole send ~/forks/fish-shell/'

vs.

complete -C 'wormhole --send ~/forks/fish-shell/'
~/forks/fish-shell/benchmarks/
~/forks/fish-shell/BSDmakefile
~/forks/fish-shell/build,/
~/forks/fish-shell/build/
~/forks/fish-shell/build_tools/
~/forks/fish-shell/CHANGELOG.rst
~/forks/fish-shell/cmake/
~/forks/fish-shell/CMakeLists.txt
~/forks/fish-shell/CODE_OF_CONDUCT.md
~/forks/fish-shell/config_cmake.h.in
~/forks/fish-shell/CONTRIBUTING.rst
~/forks/fish-shell/COPYING
~/forks/fish-shell/debian/
~/forks/fish-shell/doc_src/
~/forks/fish-shell/docker/
~/forks/fish-shell/Dockerfile
~/forks/fish-shell/etc/
~/forks/fish-shell/fish.desktop
~/forks/fish-shell/fish.pc.in
~/forks/fish-shell/fish.png
~/forks/fish-shell/fish.spec.in
~/forks/fish-shell/GNUmakefile
~/forks/fish-shell/osx/
~/forks/fish-shell/pcre2/
~/forks/fish-shell/po/
~/forks/fish-shell/README.rst
~/forks/fish-shell/share/
~/forks/fish-shell/src/
~/forks/fish-shell/tests/

@faho faho closed this as completed in 7210261 Apr 10, 2021
@faho
Copy link
Member

faho commented Apr 10, 2021

This still doesn't complete anything for wormhole send ~/, but does for wormhole --send ~/:

Yes, this is because the ~ is taken literally instead of expanded. It's a general issue with scripted completions - things like ~ and $VARIABLE won't be expanded, and there is currently no safe way to do that - #5811 would help.

Anyway, I've just pushed a fix for that pesky --force-files issue, that's what you should be using in this case.

@rouge8
Copy link
Contributor Author

rouge8 commented Apr 10, 2021

Yes, this is because the ~ is taken literally instead of expanded. It's a general issue with scripted completions - things like ~ and $VARIABLE won't be expanded, and there is currently no safe way to do that - #5811 would help.

Ahhhhh, got it.

Anyway, I've just pushed a fix for that pesky --force-files issue, that's what you should be using in this case.

Thanks for the fast fix!

@faho faho changed the title __fish_complete_path only completing the current directory when used with __fish_seen_subcommand_from complete --force-files does not work without options Apr 10, 2021
@faho faho added bug Something that's not working as intended and removed question labels Apr 10, 2021
@faho faho added this to the fish 3.3.0 milestone Apr 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants