hchbaw/auto-fu.zsh

Interesting behaviour

Closed this issue · 2 comments

joe9 commented

Hello,

I am wondering if you can help me with this issue.

Attached is the screenshot of what I am talking about: http://imgur.com/gdoaItb

On the right are 2 terminals and the different auto-fu behaviour in each.

On the right most terminal with the "history word" on top shows auto-fu completing to "etc/zsh" though the shortest match of "etc" in the "local directory" is still available.

On the other terminal, auto-foo correctly completes to "etc" and waits.

This is probably not related to auto-foo. To get the "history word" group in the list of commands, I add this line:

defs=(

  • 'history:history words:_history_complete_word'
    'commands:external command:_path_commands'
    )

to the file: /usr/share/zsh/5.0.2/functions/Completion/Zsh/_command_names

The shell/terminal to the extreme right was started with the above line in the file. The shell/terminal next to that (towards the center, with the correct auto-fu behaviour) was started without that above history line.

Just wanted to bring it to your attention for your insight/opinion.

Thanks
Joe

Hi, Joe!

Oh it's fascinating to add the "history word" group to _command_names.
Thank you very much opening it up here. I will try it out!

joe9 commented

Hello Takehi,

The above is the wrong way to go about adding history words to _command_names. As an fyi, below is an email from Bart on the subject:

Unless I'm misunderstanding your intent, you don't actually want to
change the tags from _command_names -- you just want to add another tag
that appears in completion output along with the _command_names tags?

To do this you want to replace the completer function for "-command-"
context. By default this is the _autocd completer (which is only the
default because _autocd is the only file in the completion library that
begins with "#compdef -command-").

So first make yourself a little function patterned on _autocd:

_history_or_autocd () {
  _history
  local ret=$?
  _autocd || return ret
}

And then install it for the context:

compdef _history_or_autocd -command-

To explain a bit further, the completers in the completer style are in
general attempted until one returns a zero (true, success) status, at
which point the set of possible matches is assumed to be finished. To
merge the results of several completers you have to save the staus, try
the next one, and then return success if any of those completers was
successful.

If you instead wanted to complete history and only try the defaults if no
history words matched, you could have shortcut this as

compdef '_history || _autocd' -command-

Of course whichever of these you choose has to happen after compinit is
run, otherwise _autocd will step on it when loaded.

Joe