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

Feature request: cli tab auto-completion #96

Closed
coxackie opened this issue Mar 18, 2020 · 5 comments · Fixed by #386
Closed

Feature request: cli tab auto-completion #96

coxackie opened this issue Mar 18, 2020 · 5 comments · Fixed by #386

Comments

@coxackie
Copy link

Not a bug, but a request. As it stands, the cli does not support tab auto-completion for commands and/or filenames. It would be nice to be able to be able to type for example, "maestral ex\t" and autocomplete the command for exclusion.

Perhaps more importantly, it would be also great if such auto-completion works for dropbox folder and file names, for example in the ls and exclude commands. Expanding on this last point, there are often cases where folders or files include spaces, which (at least for Linux) should be replaced by '\ '. Right now I have to manually write sometimes long folder names in the cli, or copy and paste them but then manually add backslashes to all the spaces. If tab could autocomplete these correctly, it would be a time saver.

Once again, many thanks for your great work on this.

@samschott
Copy link
Owner

Regarding the first point, maestral already has basic support for tab auto-completion. You can activate it by running the following in your shell or adding it to your startup script (such as ~/.bashrc or ~/.zshrc):

For zsh:

eval "$(_MAESTRAL_COMPLETE=source_zsh maestral)"

For bash:

eval "$(_MAESTRAL_COMPLETE =source_bash maestral)"

For fish:

eval (env _MAESTRAL_COMPLETE =source_fish maestral)

This is currently not done automatically but could be done in the future.

The second point is a bit more difficult. Auto-completing Dropbox paths would either require fetching them from the server (always up-to-date but potentially very high latency for a large number of items) or from a local cache such as the currently downloaded plus the top-level excluded paths. This is unlikely to be part of the next release but I will keep it in mind.

In the meantime, your life could be a bit easier if you enclose the whole path in quotes instead of escaping all spaces with a backslash...

@coxackie
Copy link
Author

many thanks - I see you are already having a new branch to add the first point.

Regarding the second point. Latency is an issue for sure, but it applies to other successful instances of the idea as well. for example, in Arch linuc, the package manager pacman has tab auto-complete for package queries to the server: if type sudo pacman -Si fire\t after a bit of lag it will give Display all 407 possibilities? (y or n) (too many firefox-related packages).

Alternatively, I guess one can use some form of local database (which should anyway be is used for syncing). The issues there are:

  • excluded folders will not be indexed most probably; this could be handled by in fact querying the server in these cases.
  • local database may be a bit different than the server's one, in cases of one-way syncing, or simple delay in sync.

I can see that this may be a nightmare to code, so most probably simply querying the server and accepting some lag may be best, if this feature is ever to be implemented.

@samschott
Copy link
Owner

So, I have been looking into this for both local paths (currently not supported either) and remote paths. I agree that the best option is to fetch remote paths directly from Dropbox servers.

However, making either of this play nicely with different shells will involve a lot of work. Maestral uses click to implement its CLI and click itself is currently redesigning their autocompletion to work better with paths and different shells: pallets/click#1484. It does not make sense for me start working on this myself before this is completed.

For now, I am experimenting with a convenience command to install autocompletion functions for the user's shell - but those will only use the currently built-in support.

@coxackie
Copy link
Author

makes perfect sense. many thanks!

@samschott
Copy link
Owner

It looks like click 8.0 will be released soon with much improved for shell completion. The documentation for their development version is already available here.

This should be a good starting point to support shell completion in maestral beyond the default that click provides, for instance to include auto-completion for Dropbox paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants