Skip to content
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

Merged
merged 9 commits into from
Oct 16, 2023
Merged

Conversation

sharder996
Copy link
Contributor

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.

Copy link
Collaborator

@ricab ricab left a 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.

@sharder996 sharder996 force-pushed the filter-duplicate-bash-args branch from b039691 to 7928582 Compare July 11, 2023 20:24
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #3156 (d49b6c6) into main (0a8014b) will increase coverage by 0.00%.
Report is 4 commits behind head on main.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #3156   +/-   ##
=======================================
  Coverage   88.51%   88.52%           
=======================================
  Files         240      240           
  Lines       12166    12166           
=======================================
+ Hits        10769    10770    +1     
+ Misses       1397     1396    -1     

see 1 file with indirect coverage changes

@ricab
Copy link
Collaborator

ricab commented Jul 12, 2023

Hey @sharder996, is this ready for another pass?

Copy link
Collaborator

@ricab ricab left a 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?

@sharder996
Copy link
Contributor Author

Hey @ricab, I believe the issue you addressed in your last comment is fixed. Ready for another review pass now.

@ricab
Copy link
Collaborator

ricab commented Sep 13, 2023

OK, thanks for letting me know. Enqueuing...

Copy link
Collaborator

@ricab ricab left a 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 😿

COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
for word in "${COMP_WORDS[@]}"; do
if [[ "${COMP_LINE}" == *"${word} "* ]]; then
opts=("${opts[@]/$word}")
Copy link
Collaborator

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...

Copy link
Collaborator

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:

Suggested change
opts=("${opts[@]/$word}")
opts=("${opts[@]/\b$word\b}")

@ricab
Copy link
Collaborator

ricab commented Sep 21, 2023

Hey @sharder996, thought you'd said you had something here, did you forget to push? Or did I misunderstand?

@sharder996
Copy link
Contributor Author

Hey @ricab, I've been working on it locally, but haven't been able to come up with an incantation that works yet.

@ricab
Copy link
Collaborator

ricab commented Sep 21, 2023

OK got it, thanks.

@sharder996 sharder996 force-pushed the filter-duplicate-bash-args branch from 8eeba16 to 2511a53 Compare October 3, 2023 13:16
@sharder996 sharder996 force-pushed the filter-duplicate-bash-args branch from 6b1e2cd to a2fef0e Compare October 4, 2023 03:30
Copy link
Collaborator

@ricab ricab left a 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.

@sharder996
Copy link
Contributor Author

Ugh, bash completions is just the gift that keeps on giving.

Anyways, this was an easy and should be working properly now.

Copy link
Collaborator

@ricab ricab left a 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+

bors bot added a commit that referenced this pull request Oct 13, 2023
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]>
@bors
Copy link
Contributor

bors bot commented Oct 13, 2023

Build failed:

@ricab
Copy link
Collaborator

ricab commented Oct 16, 2023

This is unrelated to mac and windows, so I am going ahead and merging.

@ricab ricab merged commit 24ca05e into main Oct 16, 2023
12 of 14 checks passed
@bors bors bot deleted the filter-duplicate-bash-args branch October 16, 2023 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants