rclone: rclone genautocomplete has problems with Bash

What is the problem you are having with rclone?

The file spawned by rclone genautocomplete generates this error when I login as root:

10:20:15 [brandizi@brandizmac ~]$ su - root
Password:
-sh: /usr/local/etc/bash_completion.d/rclone: line 266: syntax error near unexpected token `<'
-sh: /usr/local/etc/bash_completion.d/rclone: line 266: `            done < <(command rclone listremotes)'
10:20:18 [root@brandizmac ~]#

And rclone autocompletion fails to work after this (unsurprisingly).

This only happens when I login as root, all other users are fine.

What is your rclone version (output from rclone version)

14:47:13 [root@brandizmac ~]# rclone -V
rclone v1.48.0
- os/arch: darwin/amd64
- go version: go1.12.6

I have rclone installed via Homebrew. Initially I filed this same issue to them, cause I believed they are the ones adding Bash autocompletion.

Which OS you are using and how many bits (eg Windows 7, 64 bit)

14:52:44 [root@brandizmac ~]# sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G87
14:53:24 [root@brandizmac ~]#

Which cloud storage system are you using? (eg Google Drive)

OneDrive, but not relevant hereby.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

See above.

A log from the command with the -vv flag (eg output from rclone -vv copy /tmp remote:tmp)

See above.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@ncw, it seems to work, new/old bash, posix/non-posix mode, yeah! 😃

Thank @sgtpep not me 😃 Thank you!

@ncw My patch will eliminate the issue of compopt not being found on vanilla macOS bash that was reported by @marco-brandizi as:

I get this when I try to auto-complete rclone:

16:08:34 [brandizi@brandizmac luke]$ rclone ls -bash: compopt: command not found
rres-onedrive:-bash: compopt: command not found

and then it works correctly.

So, I think, it worth being merged, although the issue is not fatal and doesn’t break the autocomplete. Sorry for not providing it as a proper PR, didn’t have time for that.

The main issue of this ticket is that autocomplete is defunct when bash is run under root on vanilla macOS bash because it happened to operate in posix mode for some reason. If I understand @marco-brandizi correctly, it’s not a case for brew-installed bash.

We could debug this by placing set -x somewhere on top of bash init files to understand where set -o posix happens which enables posix mode for root. Or, we could just disable the whole autocomplete script if posix option is set (I could provide a patch for that, if needed.)

@marco-brandizi As for operation under root there’s still a way to debug it by adding set -x right after:

__rclone_handle_reply()
{

in /usr/local/etc/bash_completion.d/rclone, then restarting bash and trying to perform autocompletion.