From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Alter completion for mv
Date: Thu, 02 Oct 2014 19:09:03 -0700 [thread overview]
Message-ID: <141002190903.ZM12926@torch.brasslantern.com> (raw)
In-Reply-To: <m0jjrn$hrl$1@ger.gmane.org>
On Oct 2, 1:27pm, Daniel wrote:
}
} I would like completion of the destination argument for mv(1) to first
} complete directories. Is this possible by toggling an option, or could
} somebody help me out?
Start by telling completion that it should default to grouping matches
by tag:
zstyle ':completion:*' group-name ''
Check that you don't already have a conflicting zstyle for group-name.
Then, if mv is GNU mv (e.g. on linux), the best way is probably this:
compdef _gnu_generic mv
zstyle -e :completion::complete:mv:argument-rest: list-dirs-first \
'(( ! ${words[(I)--target-directory=*]} )) &&
compset -N "-*"; reply=( $((CURRENT > 1)) )'
Otherwise this will be mostly correct:
zstyle ':completion:*' group-name ''
zstyle -e :completion::complete:mv:: list-dirs-first \
'compset -N "-*"; reply=( $((CURRENT > 1)) )'
The "compset" in both examples discards options (-i, -v, etc.) that
might appear, so that you can tell which non-option word position you
are in. That also discards the command name itself, so you are left
with nothing but the non-option arguments, of which any after the
first one might be the destination argument.
There isn't a "list-files-first" style, but list-dirs-first splits
the completions into directories and other-files, so to get "prefer
files when -f is given" you can add
zstyle -e ':completion::complete:mv::' group-order \
'(( ${words[(I)(-f|--force)]} )) && \
reply=( other-files directories )'
Note you use ':completion::complete:mv::' for both the GNU and other
examples, otherwise this style is checked too late and compset will
have already removed the -f option from $words.
This overrides the default order (directories other-files) that the
list-dirs-first style would use. Improve the pattern in the $words
subscript if you want to also match -f when it is combined with some
other flag in the same word (-uf, maybe).
prev parent reply other threads:[~2014-10-03 2:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 13:27 Daniel
2014-10-02 21:20 ` zzapper
2014-10-03 2:09 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=141002190903.ZM12926@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).