2
  1. I'd like to write a zsh-completion script, which completes with files in a directory different from the current working directory. (I can archieve this, see below.)
  2. Additionally the user shall be able to use globbing on the completed command. How to archieve this?

Example:

Let's assume we want to complete a command called rumple. rumple takes a list of files from ~/rumple as argument (possibly nested directories/files). A valid invocation may be:

rumple pumple romple/pample

Which means rumple shall effectively work on ~/rumple/pumple and ~/rumple/romple/pample.

Now the zsh-completion script _rumple for rumple could look like:

#compdef rumple

_path_files -W ~/rumple

This completes the first part of the task: rumple p<TAB> will complete to rumple pumple (assuming there are not other files in ~/rumple starting with 'p'). However the second part is not working. rumple **/p* should complete to rumple pumple romple/pample, even if the current working directory is not ~/rumple.

Lord Bo
  • 3,152
  • 3
  • 15
  • 22

1 Answers1

1

Normally you would leave it to the user to configure this sort of behaviour via the _match completer or glob_complete option.

But you can force it to some extent as follows:

#compdef rumple
local a=( ~/rumple/**/* )
compstate[pattern_match]='*'
compadd ${a#$HOME/rumple/}
okapi
  • 1,340
  • 9
  • 17
  • I will have a look into it. Seems like I need to learn some more about zsh-completion first. – Lord Bo Nov 15 '21 at 16:53
  • Hm, I tried your example, but it doesn't work. But I will have a look into _match and glob_complete also. – Lord Bo Nov 15 '21 at 17:16