Giter Site home page Giter Site logo

Comments (2)

faho avatar faho commented on July 22, 2024

This is essentially what the completions for sudo or env do.

In principle, what you need to do is to get mytool run python to complete like python - to do that, you need to run complete -C python.

So, you need to grab the commandline, and remove "mytool run" from it.

Fish has the __fish_complete_subcommand helper function for this, and in the simplest case this would be

complete --command mytool -n "__fish_seen_subcommand_from run" -a '$(__fish_complete_subcommand --fcs-skip=2)'

where the "--fcs-skip=2" tells it to skip two tokens from the commandline - that's "mytool" and "run".

If your tool has e.g. options that come before the "run" this gets more complicated, see the sudo completions and the __fish_sudo_print_remaining_args helper function for how to do that.


Your attempt here has two issues:

  1. Because "$(complete -C)" is double-quoted, the complete -C will be run when the completions are loaded. That means if you attempt to complete something else, it will be stuck on the initial commandline
  2. complete -C reruns completions on the entire current commandline (it's the implied default if you don't give it a "fake" commandline to operate on)

from fish-shell.

patrick-kidger avatar patrick-kidger commented on July 22, 2024

Aha! This is absolutely perfect.

I also learnt a lot about fish generates completions -- the explanation for how this comes together (I just spent a bit of time fiddling with __fish_complete_subcommand to see how it works) was super useful.

Thank you so much, I really appreciate the help.

from fish-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.