Comments (8)
Well, I think that generating autocomplete automatically for this will be difficult, for several reasons:
- Positional arguments sometimes need to be completed with dir entries, or git branches, or some other non-fixed string
- 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.
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.
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:
- 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
eval
ing it in~/.bashrc
. - 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.
- 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.
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.
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.
Bash completion is now implemented in version 0.6.0, by using the bashly add comp *
set of commands.
from bashly.
Sorry for ignoring you -- life got in the way! I just wanted to thank you for implementing this.
from bashly.
No worries :)
from bashly.
Related Issues (20)
- Allow default array when repeatable is true HOT 9
- Add support for array in `flag.default` and `arg.default` schema HOT 1
- JSON schema validation passes when it shouldn't HOT 12
- Add JSON schema tests to ensure the validation fails when it should HOT 1
- Whitelisted arg with default from environment HOT 6
- Add `environment_variable.allowed` whitelist HOT 1
- Update `inspect_args` to also print managed environment variables HOT 1
- Docker container does not have pandoc installed HOT 2
- Do not render `inspect_args` when `env` is set to `production` HOT 2
- Add key-value parameters HOT 6
- Add support for recursive --help HOT 6
- Build multi-arch docker HOT 2
- Default argument is not validated HOT 6
- Flag arguments with a single hyphen prefix are not working HOT 1
- bash completions can't work properly when the position args used 'allowed:' HOT 3
- Repeatable args don't escape quotation marks HOT 12
- Add option to disable splitting of flags with value for catch_all arguments HOT 9
- Lifecycle for temporary directories HOT 1
- Heredoc indentation issue in bashly generated functions. HOT 9
- The Flag value is detected as an Argument HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bashly.