-
Notifications
You must be signed in to change notification settings - Fork 658
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
[bash] remove duplicates from completions #3156
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this doesn't seem to work for me:
$ multipass list --[TAB][TAB]
--format --help --verbose
$ multipass list --help --[TAB][TAB]
--format --help --verbose
$ multipass list --help --h[TAB]
$ multipass list --help --help
BTW, --verbose
can be used multiple times... But I guess we can overlook that for the benefit here. People would use -v
for that.
b039691
to
7928582
Compare
Codecov Report
@@ Coverage Diff @@
## main #3156 +/- ##
=======================================
Coverage 88.51% 88.52%
=======================================
Files 240 240
Lines 12166 12166
=======================================
+ Hits 10769 10770 +1
+ Misses 1397 1396 -1 |
Hey @sharder996, is this ready for another pass? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so that original issue I saw is fixed, but I have found just a little remaining problem.
In the stable channel, if I do multipass info[TAB]
, info
is completed, meaning that a space is added. With this PR, the cursor doesn't move. That's because info
is already present so it is not suggested. This means that something like multipass alias[TAB]
gets auto-completed to aliases
, instead of offering the two options as in stable.
Is there a way you can exclude the current word from the list of existing words?
Hey @ricab, I believe the issue you addressed in your last comment is fixed. Ready for another review pass now. |
OK, thanks for letting me know. Enqueuing... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Scott, I was about to approve when I noticed something 😿
completions/bash/multipass
Outdated
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
for word in "${COMP_WORDS[@]}"; do | ||
if [[ "${COMP_LINE}" == *"${word} "* ]]; then | ||
opts=("${opts[@]/$word}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sharder996, sorry, I am afraid this won't do because it can remove strings where it shouldn't. For instance, I have instances called a
and b
. Here's what completion does:
$ multipass info [TAB][TAB]
a --all b --format --help --verbose
$ multipass info a [TAB][TAB]
b --format --help --ll --verbose
It removed all "a"s from opts
, so --all
became --ll
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would work:
opts=("${opts[@]/$word}") | |
opts=("${opts[@]/\b$word\b}") |
Hey @sharder996, thought you'd said you had something here, did you forget to push? Or did I misunderstand? |
Hey @ricab, I've been working on it locally, but haven't been able to come up with an incantation that works yet. |
OK got it, thanks. |
fa239a5
to
8eeba16
Compare
…ether or not they allow duplicates
8eeba16
to
2511a53
Compare
6b1e2cd
to
a2fef0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sharder996, something still amiss 😖
$ multipass list
Name State IPv4 Image
a Stopped -- Ubuntu 18.04 LTS
b Stopped -- Ubuntu 22.04 LTS
c Stopped -- Ubuntu 23.04
$ multipass start [TAB][TAB]
--all b c --help --verbose
$ multipass shell [TAB][TAB]
b c --help --verbose
Instance a
is not in the suggestions. It is if I use stable.
Ugh, bash completions is just the gift that keeps on giving. Anyways, this was an easy and should be working properly now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, appears to be good now. Thanks!
bors r+
3156: [bash] remove duplicates from completions r=ricab a=sharder996 Bash completions will currently suggest repeated flags endlessly. This PR filters out previously seen options/flags with the assumption that no multipass currently accepts this pattern. Co-authored-by: sharder996 <[email protected]>
Build failed: |
This is unrelated to mac and windows, so I am going ahead and merging. |
Bash completions will currently suggest repeated flags endlessly. This PR filters out previously seen options/flags with the assumption that no multipass currently accepts this pattern.