-
Notifications
You must be signed in to change notification settings - Fork 233
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
command: add extensive autocompletion support #500
Conversation
add escape colon method for autocomplete parameters.
except the "version" and "mb", for which autocompletion of remote buckets/keys does not make sense.
- autocomplete used to fall back to default bash behaviour after the autocompletion suggestions are filtered. So the default bash completion completed "s5cmd ls s3://b" to "s3://bin/" since there is a directory named "/bin/" in the local. Default behavior ignores "s3:" since : is a COMP_WORDBREAK. by moving the completion fallback to compgen function we ensure that local completions are also filtered properly.
- It used to complete full s3 keys at once, but now it only completes till next s3 seperator (slash) - bucket completion now appends slash (/) to the end of the bucket
In bash
In zsh
ps. |
upgrade urfave/cli to v2.11.2 to match #495
General NotesWe are using the urfave/cli's autocompletion feature. We provide autocompletion scripts for bash, pwsh, and zsh. The essence of all three script is that:
Common problems (incomplete)If the argument that is going to be completed contains zshIts autocompletion behavior uses bashColonIn bash autocompletion behaviour uses Using COMP_LINE & COMP_POINTWhen an autocompletion request is made BASH sets calls the autocompletion script with some environment variables. COMP_WORDS is one of them. It is an array of strings created from the original command to be completed. Normally it is used in urfave/cli's autocompletion. However it splits words according to notorious COMP_WORDBREAKS and colon characters are considered to be word breaks and seperate words. It might be still tempting to use it and 'just concat when there is a colon'. ineffective completionFor pwshNot doing anything special. It is the Powershell, BTW. Manjaro KDE: zsh vs bashs5cmd reads the SHELL environment variable and prepares the autocompletions according to its value. autocompletion suggestions don't respect to the number of argumentsAutocompletions currently don't check number of arguments. For example Number of suggestions provided by s5cmdI set it to 20 to avoid excessive API calls. But we can increase or remove the limit. Bug-like behaviour in bashif
Footnotes
|
Co-Authored-By: Aykut Farsak <aykutfarsak@gmail.com>
command/auto_complete.go
Outdated
|
||
// it returns a complete function which prints the argument, itself, which is to be completed. | ||
// If the argument is empty string it uses the defaultCompletions to make suggestions. | ||
func ineffectiveCompleteFnWithDefault(cmd *cli.Command, defaultCompletions ...string) func(ctx *cli.Context) { |
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.
WDYM by ineffective? Please give it a name that indicates what it does.
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 mean it doesn't actually predict anything but merely returns the argument itself (or some default values) to override shell's default autocompletion. May be nonpredictiveCompleteFnWithDefault
can be a better name (or worse?)
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.
For the record with https://github.com/Kucukaslan/s5cmd/commit/578f64c79aa9d76206c5fe90e8435a6afad91fdb this function is split to two parts and the auto-completion function is named constantCompleteWithDefault
.
format method switch seperate PR for filter regex see storage/url: add nil check for URL.filterRegex in URL.Match #511 partially seperate completion from cli package pass shell variable through methods
…tocompletion functions
Co-authored-by: Selman Kayrancioglu <seruman@users.noreply.github.com>
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.
🚀 Thank you!
My pleasure. Thanks a lot for your help and suggestions! |
Adds extensive auto-completion support to s5cmd for zsh, bash and pwsh. Including:
The user will be given the instructions and the completion script when she called s5cmd with install-completion flag. The instructions and script will be written according to value of SHELL environment variable
Fixes #207
Fixes #372