0

I am trying to follow Make zsh complete arguments from a file but with a command. Shouldn't matter much.

In /usr/local/share/zsh/site-functions/_foo I have

#compdef foo
aliases=($(a complicated command here printing everything twice))
_describe aliases aliases

The command when ran alone prints this:

foo foo bar bar this this that that

This seems to create an associative array just fine. When I add echo ${(kv)aliases} before the _describe aliases aliases command and run /usr/local/share/zsh/site-functions/_foo I am getting

foo foo bar bar this this that that

And when I just do ${(k)aliases} then

foo bar this that

I do not really a description so this would work for me. But, it doesn't work for zsh.

I added

function foo() { echo $* }
autoload _foo
compdef _foo foo

to ~/.zshrc and after . ~/.zshrc when I type foo [tab] I get _foo:2: bad set of key/value pairs for associative array. I tried changing the command to only print everything once. Same results. I tried changing the command to print "foo:x " for every foo. Same results. So what about should my program produce for this to work?

chx
  • 11,270
  • 7
  • 55
  • 129

1 Answers1

1

aliases already exists as an associative array containing all your shell aliases. Call the variable something else.

It may alias help to declare your variable local, for a normal array:

local -a compl_aliases

The bad set of key/value pairs usually indicates that you have an odd number of elements when doing an associative array assignment. There needs to be an even number with a value for each key.

okapi
  • 1,340
  • 9
  • 17
  • Oh. That's a bummer. I will leave this up now; I posted a diffrent working solution to the linked parent question. https://stackoverflow.com/a/51550248/308851 – chx Jul 27 '18 at 22:06