From: Felipe Contreras <felipe.contreras@gmail.com>
To: zsh-workers@zsh.org
Cc: Felipe Contreras Garza <felipe.contreras@gmail.com>
Subject: No way to properly complete specific set of files
Date: Sat, 27 Apr 2013 05:12:27 -0500 [thread overview]
Message-ID: <CAMP44s1hjM94+o_xwaw=gsiwx1Y1rd12sqhunWywiTkWaJvTEQ@mail.gmail.com> (raw)
Hi,
I have an array, let's say:
files=('Documents' 'Downloads' 'Downloads/test' 'Videos')
And I want to complete those files, with all the niceties that _file has.
I could do the same as _git and others do:
_multi_parts -f -- / files
But that doesn't work; the files are not detected. And it doesn't
complete the same way.
Or I could use _path_files, as somebody suggested on the list, but
that doesn't limit the list of files.
It would have been very easy to tell _path_files which files to
complete, but no, I have to manually implement the completion myself:
---
#compdef foobar
_foobar_1 ()
{
_multi_parts -f -- / $1
}
_foobar_2 ()
{
_path_files
}
_foobar_3 ()
{
local -a list
local pfx="" cur="${words[CURRENT]}" file
case "$cur" in
?*/*)
pfx="${cur%/*}"
cur="${cur##*/}"
pfx="${pfx}/"
;;
esac
for file in ${(P)1}; do
case "$file" in
${pfx}*)
file="${file##$pfx}"
;;
*)
continue
;;
esac
case "$file" in
?*/*)
list+="${file%%/*}"
;;
*)
list+="${file}"
;;
esac
done
compadd -Q -p "${pfx-}" -f -a list
}
_foobar ()
{
local -a files
files=('Documents' 'Downloads' 'Downloads/test' 'Videos')
_foobar_3 files
return 0
}
_foobar
---
Am I missing something?
--
Felipe Contreras
next reply other threads:[~2013-04-27 10:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-27 10:12 Felipe Contreras [this message]
2013-04-28 18:12 ` Peter Stephenson
2013-04-28 23:42 ` Bart Schaefer
2013-04-29 5:39 ` Felipe Contreras
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='CAMP44s1hjM94+o_xwaw=gsiwx1Y1rd12sqhunWywiTkWaJvTEQ@mail.gmail.com' \
--to=felipe.contreras@gmail.com \
--cc=zsh-workers@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).