Quantcast
Channel: zsh shell autocomplete, how to autocomplete both files and arbitrary strings returned from a function - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

zsh shell autocomplete, how to autocomplete both files and arbitrary strings returned from a function

0
0

I'm trying to setup zsh so that it autocompletes my rclone commands, for example rclone copy gdr <tab> and it becomes rclone copy gdrive-johnsmith while also doing the same thing to file names.


rclone did come with a command to generate a zsh autocomplete file, but the file did not autocomplete remote directory names (like gdrive-johnsmith: above), just the commands like copy, listremotes, and authorize. I opened up the generated file and could not for the life of me figure out how to make zsh list the remote names (which I can get a list of using rclone listremotes) and the files together "the correct way" (no parsing ls :P). Anyways, I ended up giving up and doing just that and now my _rclone file looks something like this:

#compdef rclone

_arguments \
    '1: :->level1' \
    '2: :->level2' \
    '3: :($(rclone listremotes) $(ls))'

_arguments '*: :($(rclone listremotes) $(ls))'

The entire file is like 38 lines but I don't think there's anything relevant in there (I can post the rest if needed). The "_arguments" line used to look like this:

_arguments '*: :_files'

before I changed it to list both the remotes and files in the cwd. Like I said above, I'd like a way to be able to use _files. My current approach is ugly, breaks whenever file or folder names have a space because zsh splits em up, and it groups everything together and it looks horrible:

 17:43:06  /usr/share/zsh/vendor-completions
 » rclone copy
_bootctl                   gdrive-fakeName:           _rclone
box-fakeName:              _hostnamectl               _sd_hosts_or_user_at_host
_busctl                    _journalctl                _sd_outputmodes
_curl                      _localectl                 _sd_unit_files
dropbox-google-fakeName:   _loginctl                  _systemctl

etc...

Anyways, is there a way to, in zsh:

  • A) Use the _files function or anything that doesn't break whenever I press spacebar to autocomplete rclone remote directories?
  • B) If A is not possible, is there atleast a way to (visually) seperate the normal directories and the rclone ones?

ZSH version is 5.1.1, OS is KDE neon 5.11, oh-my-zsh installed too.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images