Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1382dba

Browse files
sgtpepncw
authored andcommitted
cmd: make autocomplete compatible with bash's posix mode rclone#3489
1 parent f134713 commit 1382dba

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cmd/help.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ documentation, changelog and configuration walkthroughs.
3939
const (
4040
bashCompletionFunc = `
4141
__rclone_custom_func() {
42-
if [[ ${#COMPREPLY[@]} -eq 0 && :$SHELLOPTS: != *:posix:* ]]; then
42+
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
4343
local cur cword prev words
4444
if declare -F _init_completion > /dev/null; then
4545
_init_completion -n : || return
4646
else
4747
__rclone_init_completion -n : || return
4848
fi
4949
if [[ $cur != *:* ]]; then
50+
local ifs=$IFS
51+
IFS=$'\n'
52+
local remotes=($(command rclone listremotes))
53+
IFS=$ifs
5054
local remote
51-
while IFS= read -r remote; do
55+
for remote in "${remotes[@]}"; do
5256
[[ $remote != $cur* ]] || COMPREPLY+=("$remote")
53-
done < <(command rclone listremotes)
57+
done
5458
if [[ ${COMPREPLY[@]} ]]; then
5559
local paths=("$cur"*)
5660
[[ ! -f ${paths[0]} ]] || COMPREPLY+=("${paths[@]}")
@@ -62,11 +66,15 @@ __rclone_custom_func() {
6266
else
6367
local prefix=
6468
fi
69+
local ifs=$IFS
70+
IFS=$'\n'
71+
local lines=($(rclone lsf "${cur%%:*}:$prefix" 2>/dev/null))
72+
IFS=$ifs
6573
local line
66-
while IFS= read -r line; do
74+
for line in "${lines[@]}"; do
6775
local reply=${prefix:+$prefix/}$line
6876
[[ $reply != $path* ]] || COMPREPLY+=("$reply")
69-
done < <(rclone lsf "${cur%%:*}:$prefix" 2>/dev/null)
77+
done
7078
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o filenames
7179
fi
7280
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o nospace

0 commit comments

Comments
 (0)