From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18055 invoked by alias); 3 Oct 2014 02:08:58 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19203 Received: (qmail 16698 invoked from network); 3 Oct 2014 02:08:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <141002190903.ZM12926@torch.brasslantern.com> Date: Thu, 02 Oct 2014 19:09:03 -0700 In-reply-to: Comments: In reply to Daniel "Alter completion for mv" (Oct 2, 1:27pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Alter completion for mv MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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).