Comments (9)
If I type
winget install Python
and hit tab, it completes the command line by turning it intowinget install "Python
. Basically, it adds double quotes at the beginning of the query and doesn't suggest anything else. I suppose this is due to the fact that there are packages that contain spaces, such asPython Launcher
. I don't know if this is the expected behaviour (I know thatwinget complete
isn't doing that).
@loriswit That's how Readline (and bash) is meant to work. The difference isn't about your script versus the new script: it's the fact that Clink v1.4.13 fixed a bug in the quoting, which had been malfunctioning before.
- The first Tab
complete
command inserts the longest common prefix from the matches that fit what's been typed so far. - Since
Python
is already the longest common prefix of everything matchingPython
, nothing is appended on the first Tab.
If it doesn't insert a quote upon Python
Tab, then it's impossible to complete anything with a space, without manually backing up and inserting a space quote. But it's conservative, and only inserts a space if the next character in any of the matches requires quoting. So typing Pyt
Tab doesn't insert a quote because the next possible characters are h
or i
. But typing Pyth
Tab will append on
(longest common prefix) and insert a quote (because the next possible characters after Python
are
or .
, one of which is a character that requires a quote (
requires a quote).
Now, if I hit tab again, absolutely nothing happens (and nothings is suggested). But if I hit tab a third time, then I receive the expected suggestion.
The complete
command prints a list of matches if the previous Tab didn't modify the input line.
And when Readline inserts a quote, it considers that as having modified the input line, so the next Tab will not print a list of matches.
Thus the 3 Tab presses needed to print a list when the first Tab inserts a quote.
P.S. You can observe the same in bash
, by creating a subdirectory and some files with the same names as from the winget completions.
Also note that if the query isn't a whole word (
Pyt
), then no quotes are being added to the query, and I only need to hit tab twice:
Since Pyt
is already the longest common prefix of everything matching Pyt
, nothing is appended on the first Tab.
If you typed Pyth
then it would append on
, making Python
, since that's the longest common prefix from the matches that fit Pyth
. And it would require 2 more Tab presses to see a list of matches.
Finally, I also realized that the script I wrote myself (see first post) was showing these kind of "inline suggestions", i.e. text in a dim color that appears after the cursor (see picture below).
The script in this repository currently does not do that.
That was intentional; see below.
By the way, notice that the auto-suggestion is Python.Python.2
. That's interesting, right? Why isn't it Python Launcher
, which is the first match for Python
? Because Python Launcher
contains a space, and cannot be inserted without also inserting a quote. But there's no way to show the quote that would get inserted, and it's misleading to insert a quote that wasn't actually shown.
With your script, try this:
- Type
winget install python
and wait for the auto-suggestion to appear. - Then rapidly type Backspace 6 times and type
a
and wait for the auto-suggestion to update. - It never will.
- Because
winget complete --word "" --commandline "winget install " --position 99999
returns no matches. - And then
winget complete --word "p" --commandline "winget install p" --position 99999
returns all matches starting withp
, and Clink caches the list. - From there on, all typing in that word position just filters the list of
p
matches.
That's why my script uses builder:setvolatile()
to disable caching.
But disabling caching means a new network query is triggered each time a letter is input or deleted. Clink throttles it so there's only one query at a time, so typing several letters in rapid succession only triggers one for the first letter. That's a lot of network traffic, and it's a little rude to hit someone's server with that much traffic. But probably the total traffic from Clink users isn't even noticeable, since Clink is a niche tool.
But there's another issue. The following would happen, if the script didn't also use coroutine.running()
to figure out when to disable the background auto-suggestion invocations of winget complete
.
- You could type
winget install python
and wait for the auto-suggestion to appear. - Then you could rapidly type Backspace 5 times and wait for the auto-suggestion to update.
- It would show
Python.Python.2
as the suggestion. - But the "correct" suggestion would by
paddiM8.kalker
, the first match forp
that doesn't contain a character that requires quoting.
The issue there has to do with internal optimizations in Clink, regarding caching and reusing match lists. But winget complete --word "" --commandline "winget install" --position 99999
returns an empty list of matches. It refuses to collect any matches unless a non-empty --word
is specified as a prefix. That prevents fetching the full list of matches (which is for the best -- the full list is huge and just keeps growing). The auto-suggestion implementation assumes that internal caching is possible, which is why it only does one query, for the first letter typed in rapid succession.
Clink could follow up with a second query after typing settles, after detecting that builder:setvolatile()
was used during background auto-suggestion match collection.
Ok, I'll do two things:
- Re-enable the auto-suggestion capability in the script. I'll do that right now, which will regain the auto-suggestion behavior, but the subtle problem will still exist (which many people might not even care about).
- Make a change in Clink to re-issue another auto-suggestion generation pass when (1) the matches are marked as volatile and (2) the input line changed since the previous auto-suggestion generation pass. That will end up resolving the issues fully.
from clink-completions.
One last question: how would you complete a multi-word query, once you started typing the second word?
❯ winget install "Python Laun<tab> <nothing>
Is it because closing quotes are missing and it's being considered a new argument?
@loriswit Thanks, I didn't notice that wasn't working. I'll look into it and find out what's happening. It might be something in Clink or it might be something in the winget.lua script.
from clink-completions.
Thanks for reporting this! Both info
and help
are bogus. It looks like they somehow survived the initial copy/paste that was used to start writing the script.
I didn't go through the whole script in details, but I suppose it doesn't rely enough on the winget complete command, which I suppose would help improving completion a lot.
At the top of the script is a comment saying that the reason it doesn't use winget complete
is because it has a lot of gaps and fails to provide a bunch of completions that it should be providing (arguments to flags, for example), and if I remember correctly I think there were even cases where it offered completions for the wrong thing entirely.
I'll see what I can do about using a hybrid approach, though.
from clink-completions.
@loriswit how do the new updates to the winget
completions work for you?
Two known issues remain:
- Until Clink v1.4.13 is released (in the new few days), completions for e.g.
winget install power
Tab won't be able to show the corresponding completions, because of a CPU busy-loop in Clink that I discovered while updating thewinget
completions script. In the meantime, the script works around the problem, and will automatically start working fully after updating to Clink v1.4.13. - Winget has added some new flags, which aren't recognized yet. I'll add them in the next couple of days. The way that
winget complete
works is insufficient to support input line coloring, it also doesn't support file or directory completions where it should, and a few other limitations. So the completion script uses a hybrid approach of both having predefined commands and flags, and also invokingwinget complete
for certain places where winget is able to provide completions for package names and versions and some other things.
from clink-completions.
@loriswit Clink v1.4.13 is released, and winget.lua
has been updated. I'll make a new release in the clink-completions repo later tonight.
If possible, it would be great to get feedback about the improvements.
from clink-completions.
Thanks, that was fast!
I just quickly tested the new versions of both clink and the completions. Looks like winget support is definitely better, but there are still a few weird things happening (note: I have default_bindings
set to bash
).
If I type winget install Python
and hit tab, it completes the command line by turning it into winget install "Python
. Basically, it adds double quotes at the beginning of the query and doesn't suggest anything else. I suppose this is due to the fact that there are packages that contain spaces, such as Python Launcher
. I don't know if this is the expected behaviour (I know that winget complete
isn't doing that).
Now, if I hit tab again, absolutely nothing happens (and nothings is suggested). But if I hit tab a third time, then I receive the expected suggestion.
❯ winget install Python<tab>
❯ winget install "Python<tab><tab>
Python Launcher Python.Python.3.0 Python.Python.3.3 Python.Python.3.6 Python.Python.3.9 Python.Python.3.12
Python Tk Gui Builder Python.Python.3.1 Python.Python.3.4 Python.Python.3.7 Python.Python.3.10
Python.Python.2 Python.Python.3.2 Python.Python.3.5 Python.Python.3.8 Python.Python.3.11
Also note that if the query isn't a whole word (Pyt
), then no quotes are being added to the query, and I only need to hit tab twice:
❯ winget install Pyt<tab><tab>
Python Launcher Python.Python.3.0 Python.Python.3.3 Python.Python.3.6 Python.Python.3.9 Python.Python.3.12
Python Tk Gui Builder Python.Python.3.1 Python.Python.3.4 Python.Python.3.7 Python.Python.3.10 pytigon
Python.Python.2 Python.Python.3.2 Python.Python.3.5 Python.Python.3.8 Python.Python.3.11
Finally, I also realized that the script I wrote myself (see first post) was showing these kind of "inline suggestions", i.e. text in a dim color that appears after the cursor (see picture below).
The script in this repository currently does not do that.
from clink-completions.
Alright, thanks for the in-depth explanations and the quick fixes!
from clink-completions.
One last question: how would you complete a multi-word query, once you started typing the second word?
❯ winget install "Python Laun<tab>
<nothing>
Is it because closing quotes are missing and it's being considered a new argument?
from clink-completions.
One last question: how would you complete a multi-word query, once you started typing the second word?
❯ winget install "Python Laun<tab> <nothing>
Is it because closing quotes are missing and it's being considered a new argument?
@loriswit This is a limitation in winget
itself. The winget complete
command apparently has no way to support quoted arguments (i.e. arguments that contain a space within them).
So that's something you'd need to take up with the winget team/repo.
from clink-completions.
Related Issues (20)
- fastboot.lua and scrcpy.lua misbehaving too HOT 1
- Unwanted behaviour for `adb` and `scrcpy` completions. HOT 6
- git.lua:155: attempt to call upvalue 'w' (a nil value) HOT 8
- Run git pull on script folders after update HOT 3
- Error when completing ssh HOT 3
- openssl.lua:1179: attempt to compare number with string HOT 1
- Error "module 'path' not found" on fresh install. HOT 8
- Sudo Clink version mismatch HOT 6
- Winget completion throws error HOT 8
- Completion for Nuke.Build HOT 12
- git add completions are git root relative instead of cwd relative HOT 2
- Git add tries to add already added (renamed/moved) file HOT 2
- RFE: add completions for ping HOT 10
- Bug: completions from known_hosts for ssh and ping on non-default port HOT 5
- The new git_prompt.lua in 0.4.9 breaks custom non-cmder prompt HOT 6
- Add completions for arduino-cli HOT 1
- How to let 'git add' completion non-recursive HOT 7
- Add completions for go and rust tools
- Test error HOT 7
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 clink-completions.