From 3c4407442db9b5adec0a8e537e7af55b1b1e4ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Gamb=C3=B6ck?= Date: Thu, 14 Mar 2019 21:59:09 +0100 Subject: [PATCH] cmd: fix completion of remotes The previous behavior of the remotes completion was that only alphanumeric characters were allowed in a remote name. This limitation has been lifted somewhat by #2985, which also allowed an underscore. With the new implementation introduced in this commit, the completion of the remote name has been simplified: If there is no colon (":") in the current word, then complete remote name. Otherwise, complete the path inside the specified remote. This allows correct completion of all remote names that are allowed by the config (including - and _). Actually it matches much more than that, even remote names that are not allowed by the config, but in such a case there already would be a wrong identifier in the configuration file. With this simpler string comparison, we can get rid of the regular expression, which makes the completion multiple times faster. For a sample benchmark, try the following: # Old way $ time bash -c 'for _ in {1..1000000}; do [[ remote:path =~ ^[[:alnum:]]*$ ]]; done' real 0m15,637s user 0m15,613s sys 0m0,024s # New way $ time bash -c 'for _ in {1..1000000}; do [[ remote:path != *:* ]]; done' real 0m1,324s user 0m1,304s sys 0m0,020s --- cmd/help.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/help.go b/cmd/help.go index 3bbe191ec..16f001e1d 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -45,7 +45,7 @@ __rclone_custom_func() { else __rclone_init_completion -n : || return fi - if [[ $cur =~ ^[[:alnum:]_]*$ ]]; then + if [[ $cur != *:* ]]; then local remote while IFS= read -r remote; do [[ $remote != $cur* ]] || COMPREPLY+=("$remote") @@ -54,7 +54,7 @@ __rclone_custom_func() { local paths=("$cur"*) [[ ! -f ${paths[0]} ]] || COMPREPLY+=("${paths[@]}") fi - elif [[ $cur =~ ^[[:alnum:]_]+: ]]; then + else local path=${cur#*:} if [[ $path == */* ]]; then local prefix=${path%/*}