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
Tab-completion for remote paths #1529
Comments
What this needs is is magic in the auto completion script. This would have to call rclone to get a listing of the remote at the correct time. I could really do with help on this one as bash auto completion is a bit of a mystery to me! |
If you manage to get this working (it would be quite magical!), please look at crypt'ed remotes, as these are particularly difficult to navigate at present by any means other than a fuse mount. |
I have a little experience bash scripting. The main issue with this is how portable rclone is. To get proper bash completion support you need to have a script which loads the autocompletion function into the bash environment. Normally this is done by putting the script in a specific folder. You could also include a bash script with go or perhaps the best solution is to have rclone modify the necessary environment variables with a flag (example: rclone --init_autocomplete) for example. There are also clever approaches to abuse go packages to manage autocomplete for you. The second approach is probably the best one to use. rclone would need to be able to "install" and uninstall it's autocompletion scripts though, that could be easily done with command flags though. |
I'd be happy to get tab completion for just the names of remotes to get things started. For example, when typing |
@aurelg that looks very interesting. @cspeterson would you like to contribute your rclone tab completion script to rclone? Rclone has a bash completion script already generated by cobra: https://rclone.org/commands/rclone_genautocomplete_bash/ so we'd have to figure out how to join the two together. |
@ncw I'd be happy to work on that. Question though: do all possible rclone targets construct paths the same way? I only designed and tested my script to work with GDrive and it makes some assumptions there |
@cspeterson A couple things I noted:
Also, I'm super-excited for this to get into the core. |
|
@cspeterson wrote:
:-)
Yes all remotes construct paths in the same way remote:path/path/path. A small number of remotes will do something different if you do remote:/path/path/path (eg sftp which will look from the root rather than from the users home directory). |
Bump :) I believe there are similar auto completion scripts for |
Here's my version of completion for remotes (heavily based on @cspeterson's script): https://raw.githubusercontent.com/sgtpep/dotfiles/master/.bash_completion. Should play fine with |
Nice one! How do you install it? Do you want to contribute this to the rclone repo? |
@sgtpep nice! I'll be using your update for sure this reminder brings me to share that I spent some time struggling with getting this script into the project but i hit a wall at some point and haven't found the time since. Perhaps @sgtpep is better equipped to get this done in a timely fashion? ¯\(ツ)/¯ |
@ncw, @cspeterson Thanks!
For now I just keep https://raw.githubusercontent.com/sgtpep/dotfiles/master/.bash_completion as
I'd love to. It probably requires some modifications to make it compatible with |
I'm not quite sure of the best way of incorporating this into rclone... It could be as part of the |
@ncw Sorry for the delay. This seems to work on my /usr/share/bash-completion/completions/rclone: https://gist.github.com/sgtpep/c95a50f8980a143bef8f7176d9013710. It supposedly should work on macOS/Homebrew, but couldn't test. |
I managed to work out (eventually!) how to add this to the cobra framework bash completion generator. I Can you give it a go here? https://beta.rclone.org/branch/v1.45-175-g871ae1f1-fix-1529-bash-completion-beta/ (uploaded in 15-30 mins) Here is the commit 871ae1f to show you where it is. I realise I've forgotten to attribute @sgtpep so I'll change that after a round of feedback. Do you think this should be on by default? It seems to work very well, but it does have the downside that it interferes with local completions. What other testing does it need? |
Indeed, updated gist. Here is the diff of that diff :) https://gist.github.com/sgtpep/c95a50f8980a143bef8f7176d9013710/revisions.
Has anyone tried it on stock macOS bash 3.* and/or recent bash from Homebrew? |
That is great - thank you! Merging the completions for the remotes and the local file names is brilliant! I wish I understood how it worked - it all just looks like magic to me ;-) I integrated the changes into rclone here https://beta.rclone.org/branch/v1.45-177-ga969e259-fix-1529-bash-completion-beta/ (uploaded in 15-30 mins)
I tried to find a linux server with bash3 but looks like the distros went to bash4 a long time ago! Unfortunately I don't have a mac. Does anyone else want to give it a test? @sgtpep Do you think I should merge this for the v1.46 release (which is due at the weekend)? |
Thank you! It looks all good to me. I'd really love to see this change in the new release, and my guess is that that addition won't break or affect the rest of completion code, at least other locations of completion should remain working. The problem with macOS is not only really vintage bash which some people replace with a version from Homebrew. Homebrew provides (or provided) a version of bash-completion that is different from one on linuxes and lacks |
Great!
I put a call for testers on the forum. |
I've merged this to master in 60a4a8a now which means it will be in the latest beta in 15-30 mins and released in v1.46 Thank you all for your help, especially @cspeterson and @sgtpep |
Thanks to: - Christopher Peterson (@cspeterson) for the original script - Danil Semelenov (@sgtpep) for many refinements
This seems to conflict with bash completion for kubectl on homebrew for osx. With rclone bash completion active, kubectl get tab tab no longer works. |
Do the rclone completions work on their own? Which version of bash are you using? @sgtpep any ideas? |
@ncw I was able to reproduce it downloading recent binaries of
And Looks like there is a name clash between function from both completion scripts. They both contain functions named |
Ah well spotted. It looks like this is was an existing cobra issue: spf13/cobra#694 which has been fixed by spf13/cobra#730 However because of spf13/cobra#259 cobra hasn't had a release so rclone is still using the old version of cobra without that support. (I did try the So this should be quite easy to fix with a new cobra version and a minor tweak diff --git a/cmd/help.go b/cmd/help.go
index 59adc489a..066963fff 100644
--- a/cmd/help.go
+++ b/cmd/help.go
@@ -37,7 +37,7 @@ documentation, changelog and configuration walkthroughs.
const (
bashCompletionFunc = `
-__custom_func() {
+__rclone_custom_func() {
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
local cur cword prev words
if declare -F _init_completion > /dev/null; then |
Before this change, rclone used the `__custom_func` hook to control the completions of remote files. However this clashes with other cobra users, the most notable example being kubectl. Upgrading cobra to master allows us to use a namespaced function `__rclone_custom_func` which fixes the problem. Fixes #1529
@felder I've put a fix for this here https://beta.rclone.org/branch/v1.46.0-019-g8209f321-fix-1529-completions-beta/ (uploaded in 15-30 mins) Run |
Looks good. kubectl get tab tab does the right thing now as does rclone tab tab Thanks for the quick fix! |
Before this change, rclone used the `__custom_func` hook to control the completions of remote files. However this clashes with other cobra users, the most notable example being kubectl. Upgrading cobra to master allows us to use a namespaced function `__rclone_custom_func` which fixes the problem. Fixes #1529
Thanks for testing. I've merged this to master now which means it will be in the latest beta in 15-30 mins and released in v1.47 |
Hi, The bash completion seems to work but doesn't escape remote path containing spaces or special characters (like parenthesis).
completes to
Also it doesn't complete if the remote path is quoted although rclone does seem to support quoted remote paths:
(should I open an issue for this maybe?) thanks |
@aureliendavid Can you make a new issue about this please :-) |
Thanks to: - Christopher Peterson (@cspeterson) for the original script - Danil Semelenov (@sgtpep) for many refinements
Before this change, rclone used the `__custom_func` hook to control the completions of remote files. However this clashes with other cobra users, the most notable example being kubectl. Upgrading cobra to master allows us to use a namespaced function `__rclone_custom_func` which fixes the problem. Fixes rclone#1529
Thanks to: - Christopher Peterson (@cspeterson) for the original script - Danil Semelenov (@sgtpep) for many refinements
Before this change, rclone used the `__custom_func` hook to control the completions of remote files. However this clashes with other cobra users, the most notable example being kubectl. Upgrading cobra to master allows us to use a namespaced function `__rclone_custom_func` which fixes the problem. Fixes rclone#1529
It seems this feature is not supported for zsh autocompletion? |
In bash, the completions don't seem to cache. Which makes it very slow. |
In theory
Is there a standard way of caching completions? |
It completes the options, but not the remote paths.
I don't know, I am not familiar with the completion systems. I just wrote a custom script for myself that caches
|
That is a nice solution 😃It sounds a bit specialized to add to rclone though. |
Two years latter and still no resolution? So many partial solutions, but nothing built-in. Right now, after typing rclone copy and then "a remote": (I celebrate to remember), then TAB twice, and the listing I get is from the directory that I am in at local storage. |
@eoinkennedy this works fine for me with
|
@ncw Btw I tested it (remote path completion) on bash and it works perfectly, so the issue seems to be with the zsh completion |
I believe
rsync
andscp
can tab-complete remote paths. It would be nice to have this inrclone
too. Here's some Stack Exchange discussion of the issue.The text was updated successfully, but these errors were encountered: