From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Completion: Add _lua
Date: Mon, 23 Jul 2018 01:50:05 -0500 [thread overview]
Message-ID: <84B28497-6E79-439D-BFB5-CDD32D6BECB5@dana.is> (raw)
Add completion for the Lua command-line interpreter.
_lua_libraries is maybe a little excessive, tbh, but i found it useful — i don't
think there's any 'official' way to do what it does.
dana
diff --git a/Completion/Unix/Command/_lua b/Completion/Unix/Command/_lua
new file mode 100644
index 000000000..e11cd226c
--- /dev/null
+++ b/Completion/Unix/Command/_lua
@@ -0,0 +1,48 @@
+#compdef lua -P lua[0-9.-]##
+
+# Complete lua library names. We go out of our way here to support sub-modules
+# (of the format foo.bar.baz), even though the way `lua -l` handles those isn't
+# very nice, because it might be useful for informational purposes
+(( $+functions[_lua_libraries] )) ||
+_lua_libraries() {
+ local p
+ local -a tmp tmp2 pre
+
+ # Lua will tell us its effective search paths in the error message
+ tmp=( ${(f)"$( _call_program libraries $words[1] -l '"%%FAKE%%"' 2>&1 )"} )
+
+ [[ $tmp == *'%%FAKE%%'* ]] && {
+ tmp=( ${(@M)tmp:#*no file*'%%FAKE%%'*} )
+ tmp=( ${(@)tmp##[[:space:]]#no file[[:space:]\'\"]##} )
+ tmp=( ${(@)tmp%%[[:space:]\'\"]##} )
+
+ for p in $tmp; do
+ pre+=( ${(b)p%%'%%FAKE%%'*} )
+ # Don't recurse infinitely into the current directory; we'll just trust
+ # that all other paths are sensible
+ if [[ $p == './%%FAKE%%'* ]]; then
+ tmp2+=( ${~${${(b)p}/'%%FAKE%%'/'*'}}(#qN) )
+ else
+ tmp2+=( ${~${${(b)p}/'%%FAKE%%'/'**/*'}}(#qN) )
+ fi
+ done
+
+ tmp=( $tmp2 )
+ tmp=( ${(@)tmp%%(.lua|/init.lua|.so)} )
+ tmp=( ${(@)tmp##(${~${(j<|>)pre}})} )
+ tmp=( ${(@u)${(@)tmp//\//.}} )
+ }
+
+ _wanted -x libraries expl 'Lua library' compadd -a "$@" - tmp
+}
+
+# Stacking not supported, no arguments are exclusive except `-`
+_arguments -S -A '-*' : \
+ '*-e+[execute specified command string]:command string' \
+ '-E[ignore environment variables]' \
+ '-i[enter interactive mode]' \
+ '*-l+[specify library or module to require]: :_lua_libraries' \
+ '-v[display version information]' \
+ '(1 -)-[stop argument parsing and execute script on stdin]' \
+ '1:Lua script:_files' \
+ '*:script argument'
next reply other threads:[~2018-07-23 6:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 6:50 dana [this message]
2018-07-23 11:40 ` dana
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=84B28497-6E79-439D-BFB5-CDD32D6BECB5@dana.is \
--to=dana@dana.is \
--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).