From 1382dba3c8cfd897e1d859818b656b54b1fcdf8c Mon Sep 17 00:00:00 2001 From: Danil Semelenov Date: Fri, 6 Sep 2019 15:11:08 +0300 Subject: [PATCH] cmd: make autocomplete compatible with bash's posix mode #3489 --- cmd/help.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/help.go b/cmd/help.go index 3874db1e9..963678ce2 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -39,7 +39,7 @@ documentation, changelog and configuration walkthroughs. const ( bashCompletionFunc = ` __rclone_custom_func() { - if [[ ${#COMPREPLY[@]} -eq 0 && :$SHELLOPTS: != *:posix:* ]]; then + if [[ ${#COMPREPLY[@]} -eq 0 ]]; then local cur cword prev words if declare -F _init_completion > /dev/null; then _init_completion -n : || return @@ -47,10 +47,14 @@ __rclone_custom_func() { __rclone_init_completion -n : || return fi if [[ $cur != *:* ]]; then + local ifs=$IFS + IFS=$'\n' + local remotes=($(command rclone listremotes)) + IFS=$ifs local remote - while IFS= read -r remote; do + for remote in "${remotes[@]}"; do [[ $remote != $cur* ]] || COMPREPLY+=("$remote") - done < <(command rclone listremotes) + done if [[ ${COMPREPLY[@]} ]]; then local paths=("$cur"*) [[ ! -f ${paths[0]} ]] || COMPREPLY+=("${paths[@]}") @@ -62,11 +66,15 @@ __rclone_custom_func() { else local prefix= fi + local ifs=$IFS + IFS=$'\n' + local lines=($(rclone lsf "${cur%%:*}:$prefix" 2>/dev/null)) + IFS=$ifs local line - while IFS= read -r line; do + for line in "${lines[@]}"; do local reply=${prefix:+$prefix/}$line [[ $reply != $path* ]] || COMPREPLY+=("$reply") - done < <(rclone lsf "${cur%%:*}:$prefix" 2>/dev/null) + done [[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o filenames fi [[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o nospace