Coder Social home page Coder Social logo

Generate Bash autocompletion about bashly HOT 8 CLOSED

iamjackg avatar iamjackg commented on May 24, 2024
Generate Bash autocompletion

from bashly.

Comments (8)

DannyBen avatar DannyBen commented on May 24, 2024

Well, I think that generating autocomplete automatically for this will be difficult, for several reasons:

  1. Positional arguments sometimes need to be completed with dir entries, or git branches, or some other non-fixed string
  2. Bashly allows you to generate fairly complex command line utilities, which in turn, will cause its autocomplete to be complex - see the autocomplete for git - can you imagine generating this automatically?

I am open to suggestions that might help mitigate these issues.

from bashly.

iamjackg avatar iamjackg commented on May 24, 2024

There are two reasons the git autocomplete you linked is so complex.

One is that git has hundreds of commands/subcommands: a lot of the functions in there are very simple, they're just listing all the options for all the commands. This is something that Bashly should have enough information to generate automatically, right? It might end up being a bit ugly with very deeply-nested Bash code, but as long as it's generated automatically it should be fine... Even limiting completion to the basic available commands/flags would already be of value, and Bash will automatically include dirs/files in the autocompletion for your if you tell it to.

The other reason is that git's autocomplete does have logic to complete almost everything: branches, refs, tags, etc. I feel that Bashly can definitely get away without doing this, for now. The ability to deal with custom types like git branches is something that should probably be left to the user, and creating a framework for it can definitely be a separate issue, to be addressed later... Or never! 😆

from bashly.

DannyBen avatar DannyBen commented on May 24, 2024

It is not only git autocomplete that is complex. Looking at most autocomplete scripts, they are complex beyond the ability of an automated tool to generate them.

In all the implementations of autocomplete that I do for my tools, I am using the simple form below:

# autocompletions for the command "dns"
complete -W "flush stats --flush help" dns

One hint to support my argument, is that there is no tool (to my knowledge) that receives a simple configuration file, and generates an autocomplete script.

I am not saying it is impossible to do, but that it seems to be more complex than just strapping a few loops together.

This brings me to the following thought:

  1. It would be nice to have a standalone tool that receives a configuration YAML as input, and produces an autocomplete script as output - possibly one that you can just put in the completions dir, instead of evaling it in ~/.bashrc.
  2. If this tool is developed as a ruby gem, Bashly can use it - then it will only need to transform the actual bashly data structure, to an input suitable for that tool.
  3. The input for such a tool should be simple and declerative, and allow to define which "places" in the command can accept dir entries, and which places can accept a custom user function (for example, to implement things like git branches).

I imagine an input YAML can/should look something like this:

- pattern: git <command>
  command:
    list:
      - pull
      - push
      - commit
      - branch

- pattern: git pull [<option>] <repository> <ref>
  option:
    list:
      - -q
      - --quiet
      - --ff
      - --no-ff
  repository:
    use: dir-entries
  ref:
    command: git show-ref -s

from bashly.

iamjackg avatar iamjackg commented on May 24, 2024

Thank you for the response! Just wanted to you to know that I haven't forgotten about this :) I just haven't had much time to think about it. A lot of the CLI frameworks I've used don't produce a Bash autocompletion script, but can respond to Bash autocompletion requests when called with a certain flag, which I recognize is not necessarily a pattern that applies to this case. Your points make sense!

from bashly.

DannyBen avatar DannyBen commented on May 24, 2024

If this is still of any interest:

I have developed a separate gem that creates bash completions from a simple YAML file. The gem is called completely and is extremely easy to use, I hope.

In addition, I started integrating it in Bashly (not ready yet) - #84

from bashly.

DannyBen avatar DannyBen commented on May 24, 2024

Bash completion is now implemented in version 0.6.0, by using the bashly add comp * set of commands.

from bashly.

iamjackg avatar iamjackg commented on May 24, 2024

Sorry for ignoring you -- life got in the way! I just wanted to thank you for implementing this.

from bashly.

DannyBen avatar DannyBen commented on May 24, 2024

No worries :)

from bashly.

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.