Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

# Matching anywhere in a full path

• X-seq: zsh-users 20157
• From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
• To: zsh-users@xxxxxxx
• Subject: Matching anywhere in a full path
• Date: Mon, 13 Apr 2015 22:06:21 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=GF/2dnnrKQnVejp9PCE/r15rpMc1PxQ665Htoy3wLiU=; b=d6hjC3hPfWoNDB/uXy0V/lMDBV+J2U6NZuaMIgzhrkKlzxL7hQupxuYooszVeQukJb kMM9aJfoHItHr0NA3VHfPa72oJPv18QNyyeybihpmvLNaw47RHkh+rE4fAA/HWl3KWc4 C1FW9kZe8Vbpwh6kc26AZ96ko1hUEvm+z+2g86Cmm6k4jozayuKv+2HV+uhlxsvgtJcj WJBYpPVNA+6LVTlIBzEkCbn4a4zmImm0GKRCxk5wHJE0299RQ8oUJsXHNPWql2qbGnQa k9IQxbN+IL2A+8bIk0PFlgR4FAUV1NJkglFAI6d1jscCnKeLer3u3f0QcuW/DHGIIBsZ T46A==
• List-help: <mailto:zsh-users-help@zsh.org>
• List-id: Zsh Users List <zsh-users.zsh.org>
• List-post: <mailto:zsh-users@zsh.org>
• Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm

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=("${(@f)$(find /etc/ -type f)}") # This is just a stand-in for my
real function
}

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 on
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 using
_gen-result, the whole path should be examined for a match?


Messages sorted by: Reverse Date, Date, Thread, Author