From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28860 invoked by alias); 13 Apr 2015 21:10:33 -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: 20160 Received: (qmail 21890 invoked from network); 13 Apr 2015 21:10:20 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=WR7XZsBKT0RMujJ6H/OGO7rlRkx4Pq8jC6QemOiOwSQ=; b=ZJZJgdbNWgnlM1EqgI/gv4ylNJ1bWw/g0cgAi77/PzT4qLCOxEGzA6PLZIevO83FTh h79RGUihdaj7ewtltNPa4zBSl40LexL6VrvKyUUc1r8/RC6Jeqoaph/7Gvd1uYootgI5 bu5zBo9ENYknCPvjk8Vb+LHK3L1wBLkw+tU0XwSOeEKKdQIvk//dJtjdlbtTeptMkYpb ExYo/i0xCvBe3wAB/CMc1OpEFgVZrASZrOSsmbr6eXAXsUyVqnowKCuIxbakjM+9UMcG dewoXTuvngujQfEejf18Q9dVlu3niXY9JlNQ81nMgAk44zmyr5FZ0qAkz84WAOQ3mLAk fj+Q== MIME-Version: 1.0 X-Received: by 10.107.132.223 with SMTP id o92mr24382717ioi.49.1428959415580; Mon, 13 Apr 2015 14:10:15 -0700 (PDT) In-Reply-To: References: Date: Mon, 13 Apr 2015 23:10:15 +0200 Message-ID: Subject: Re: Matching anywhere in a full path From: Mikael Magnusson To: =?UTF-8?Q?Jesper_Nyg=C3=A5rds?= Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Apr 13, 2015 at 10:06 PM, Jesper Nyg=C3=A5rds wrote: > I am working on an idea with a completion function that generates file > paths, absolute or relative. Below is a simplified version of what I am > trying to do. I have replaced what I'm really using to generate the paths > with a call to "find", just to make it simple to see what I am stumbling = on. > > Here's how I've set up the function: > > _gen-result() { > local -a hlist > hlist=3D("${(@f)$(find /etc/ -type f)}") # This is just a stand-in fo= r my > real function > compadd -- $hlist > } > > zle -C gen-comp menu-complete _gen-result > bindkey '\ee' gen-comp > > I works well. Typing "ls <\ee>" I get the files found below /etc. > > Here's what I don't know how to solve: I would like to type some string o= n > the command line, and I want to have that string working as a filter for > the suggestions, matching anywhere in the path. Say I have "/etc/foo", > "/etc/bar" and /etc/baz/foo.txt", and I type "ls foo <\ee>", I only want > "/etc/foo" and "/etc/baz/foo.txt" to be suggested. In other words, I want > the completion to match against the string anywhere in the full path. > > In this particular example, I realize I could pass the filter string as a > restriction to the find command, and I could also filter the array "hlist= " > after the paths are generated, but that is not so simple in my real > command. Is there a way to specify in a more "zsh like" way that when usi= ng > _gen-result, the whole path should be examined for a match? If you have an array foo, and a string bar, you can return all elements that contain $bar by doing ${(M)foo:#*$bar*} (Without the (M), the matching elements will be removed). Eg, compadd -- ${hlist:#*$filter*} If this is already what you mean by "that is not so simple in my real command", then your example is too simplified :). --=20 Mikael Magnusson