* Complete certain external commands separately by path?
@ 2017-09-12 2:08 dana
2017-09-12 7:32 ` dana
0 siblings, 1 reply; 3+ messages in thread
From: dana @ 2017-09-12 2:08 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
Hey again,
I have a problem that i hope can be solved with `zstyle` somehow: I want to
make it so that when i complete external commands, zsh gives me the
possibilities from one particular directory ahead of (and ideally separate
from) all the others. Seems like the most reasonable way to do that might
be to create some kind of sub-group that i can put up top with `zstyle ...
group-order` or whatever?
Here's a contrived illustration of what i mean:
Given a PATH like this:
% print $PATH
/bin1:/bin2
And executables spread across that PATH like this:
% ls /bin1 /bin2
/bin1:
foo1 foo2
/bin2:
foo3 foo4
My current completion behaviour looks like this:
% foo<tab>
completing external command:
foo1 foo2 foo3 foo4
What i *want* is to pull the /bin2 possibilities out into their own group
so i can have them completed first — so i'd have something like this:
% foo<tab>
completing favoured external command:
foo3 foo4
completing external command:
foo1 foo2
Is there an easy way to do this?
Cheers!
dana
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Complete certain external commands separately by path?
2017-09-12 2:08 Complete certain external commands separately by path? dana
@ 2017-09-12 7:32 ` dana
2017-09-14 6:48 ` Daniel Shahaf
0 siblings, 1 reply; 3+ messages in thread
From: dana @ 2017-09-12 7:32 UTC (permalink / raw)
To: zsh-users; +Cc: dana geier
[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]
Actually, i think someone on IRC has pointed me in the right direction.
Here's my take on their suggestion, applied to my example above:
# Put a `commands-bin2` tag ahead of the regular `commands` one
zstyle ':completion:*:-command-:*' tag-order 'commands:-bin2:favoured\
external\ command commands *'
# Have `commands-bin2` ignore any command whose hashed path does NOT match
`/bin2/*`
zstyle ':completion:*:-command-:*:commands-bin2' ignored-patterns
"^(${(kj<|>)commands[(R)/bin2/*]})"
# Optionally, have `commands` ignore any command whose hashed path DOES
match `/bin2/*`
# (otherwise they'll appear in both groups — matter of preference)
zstyle ':completion:*:-command-:*:commands' ignored-patterns
"(${(kj<|>)commands[(R)/bin2/*]})"
If you can think of anything wrong with this method please let me know.
Otherwise it seems to work so far!
dana
On 11 September 2017 at 21:08, dana <dana@dana.is> wrote:
> Hey again,
>
> I have a problem that i hope can be solved with `zstyle` somehow: I want
> to make it so that when i complete external commands, zsh gives me the
> possibilities from one particular directory ahead of (and ideally separate
> from) all the others. Seems like the most reasonable way to do that might
> be to create some kind of sub-group that i can put up top with `zstyle
> ... group-order` or whatever?
>
> Here's a contrived illustration of what i mean:
>
> Given a PATH like this:
>
> % print $PATH
> /bin1:/bin2
>
> And executables spread across that PATH like this:
>
> % ls /bin1 /bin2
> /bin1:
> foo1 foo2
>
> /bin2:
> foo3 foo4
>
> My current completion behaviour looks like this:
>
> % foo<tab>
> completing external command:
> foo1 foo2 foo3 foo4
>
> What i *want* is to pull the /bin2 possibilities out into their own group
> so i can have them completed first — so i'd have something like this:
>
> % foo<tab>
> completing favoured external command:
> foo3 foo4
> completing external command:
> foo1 foo2
>
> Is there an easy way to do this?
>
> Cheers!
> dana
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Complete certain external commands separately by path?
2017-09-12 7:32 ` dana
@ 2017-09-14 6:48 ` Daniel Shahaf
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2017-09-14 6:48 UTC (permalink / raw)
To: dana; +Cc: zsh-users
dana wrote on Tue, Sep 12, 2017 at 02:32:50 -0500:
> # Put a `commands-bin2` tag ahead of the regular `commands` one
> zstyle ':completion:*:-command-:*' tag-order 'commands:-bin2:favoured\ external\ command commands *'
> zstyle ':completion:*:-command-:*:commands-bin2' ignored-patterns "^(${(kj<|>)commands[(R)/bin2/*]})"
> zstyle ':completion:*:-command-:*:commands' ignored-patterns "(${(kj<|>)commands[(R)/bin2/*]})"
>
> If you can think of anything wrong with this method please let me know.
> Otherwise it seems to work so far!
It only affects command names that are completed at command position,
i.e., it affects this:
% <TAB>
but not any of these:
% command <TAB>
% env X=Y <TAB>
% rsync -e <TAB>
⋮
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-14 6:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-12 2:08 Complete certain external commands separately by path? dana
2017-09-12 7:32 ` dana
2017-09-14 6:48 ` Daniel Shahaf
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).