zsh-users
 help / color / mirror / code / Atom feed
* Ignore commands if autocomplete to directory is possible
@ 2014-04-25  3:41 Prateek Agarwal
  2014-04-25  8:01 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Prateek Agarwal @ 2014-04-25  3:41 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]

I am an old loyal user of ZSH but this is my first community mail. Pardon
me for any errors.

I am using setopt auto_cd. But when autocompleting for directories, i want
that first preference is to be given to directories than to commands. Which
means, if directory is present that matches the substring then zsh should
not search for commands.

For examples, if i type 'ex' and then press <tab> and an 'examples'
directory was present it should get autocompleted. If 'examples' directory
is not there, then it should options for 'exit' 'exec' etc commands. This
would make cd'ing to directories much more faster.

There should be some neat zstyle completion for this, but i am not able to
figure that out. Closest related thread was : disable substring match on
command name <http://www.zsh.org/mla/users/2014/msg00279.html>. But it was
hard for me to tweak it to my needs.

Is there some good completion style possible for this?

PS: My completion zstyle is currently using oh-my-zsh's
completion.zsh<https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/completion.zsh>

Thanks.
-- 
Prateek Agarwal
MSCS, UT Austin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ignore commands if autocomplete to directory is possible
  2014-04-25  3:41 Ignore commands if autocomplete to directory is possible Prateek Agarwal
@ 2014-04-25  8:01 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2014-04-25  8:01 UTC (permalink / raw)
  To: zsh-users

On Apr 24, 10:41pm, Prateek Agarwal wrote:
}
} I am using setopt auto_cd. But when autocompleting for directories, i want
} that first preference is to be given to directories than to commands. Which
} means, if directory is present that matches the substring then zsh should
} not search for commands.

Hmm.  Ordinarily you'd do this with the tag-order style like

    # Note this does not actually work
    zstyle ':completion:*:-command-::' tag-order \*-directories

(the "everything else" is implied if no directories match).  However,
this doesn't work for autocd because the _autocd function explicitly
calls _command_names before testing the autocd option and then calling
_cd.  So there's no way to exclude command names with a style in this
context, except by *always* exluding them (which you don't want).

You have two options.

You can replace the _autocd function with this:

    _autocd() { [[ -o autocd ]] && _cd || _command_names }

Or you can use a group-order style:

    zstyle ':completion:*:-command-::' group-order \*-directories

which will cause all the directory names to appear first in the menu,
even though any commands that match will also appear.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-25  8:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-25  3:41 Ignore commands if autocomplete to directory is possible Prateek Agarwal
2014-04-25  8:01 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).