Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
No way to properly complete specific set of files
- X-seq: zsh-workers 31341
- From: Felipe Contreras <felipe.contreras@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: No way to properly complete specific set of files
- Date: Sat, 27 Apr 2013 05:12:27 -0500
- Cc: Felipe Contreras Garza <felipe.contreras@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type; bh=4075y7rdaIXQ1SIILUmoka32vtENfT7/vxtDdhvA1QA=; b=HXVaL9/KW3TH0wZDPHHbU+eubTe15hB96yTBWfd4D4/NXOBkkPk7PKNNwHpnKloo8F LhGUN3IsvcaDR90yReJ+osQcLzM7a3+xYNeesZyjzaDA8qn/meJQbzJVgTp29bMjN6C4 BX2Pmpszj0nrlRtCXnwqCjnoJAZdqG3XnPLvaicwq08g5sD1VRdjpjxsyrBYGnL/LoN3 fH4CbtURlyBmh5ffZYtcRAiKNYN93kuaCRj2O3viLV3yGuN/DK8CZT7MN15YKLeSodlQ /Ef3J/yotm0bksvPHMSG6N5K+kidzY9TV+CTuV6rqmkiuHX7D5tTq/Nmbs5MNbVFXP1B 0GBw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author