From: "Jesper Nygårds" <jesper.nygards@gmail.com>
To: zsh-users@zsh.org
Subject: Matching anywhere in a full path
Date: Mon, 13 Apr 2015 22:06:21 +0200 [thread overview]
Message-ID: <CABZhJg9ZqCXZfJ1XJha36Oe3vLxCsHmB3fvoowGN7OLPPYZGLw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1406 bytes --]
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
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 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?
next reply other threads:[~2015-04-13 20:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 20:06 Jesper Nygårds [this message]
2015-04-13 21:10 ` Mikael Magnusson
2015-04-14 5:13 ` Bart Schaefer
2015-04-14 7:09 ` Jesper Nygårds
2015-04-14 1:30 ` Jan Larres
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=CABZhJg9ZqCXZfJ1XJha36Oe3vLxCsHmB3fvoowGN7OLPPYZGLw@mail.gmail.com \
--to=jesper.nygards@gmail.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).