Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Completion: Add _lua
- X-seq: zsh-workers 43202
- From: dana <dana@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Completion: Add _lua
- Date: Mon, 23 Jul 2018 01:50:05 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=PXJ8cfwXipuWvjcUkhJfQeaeEuF1tUoB0eKrslJ/GQ8=; b=QvW+/slwN38tZAiZeqxrHIyjVeHHX9NsjhNDHtBuWLHoC9z6NErlH50FmbkoAoRIds vyro8IF/8cXpqKcn+W2U7/UI3ncNzG8EjNmCQ7SSZFrAoIxg5gJXsjg8kW5UEQUMnisu BXBKxrB4Q0yUiw94T/I73Fetav87kTGxLRgQhdpimxJoAYKifKWho/KhcTU5FG7kfqhm +8D/cdbDeA3OEdhm6XfPKQJpuJvRvLjaDf8fZ1qmXCT9mnoCxpLVkfHQBzLB2k8xvMG8 NEBdwrdUe3YxI4XOAfAItFKkUNHwTy9X097cQuznVeLoPD+l03gQRpbcDfFkRrUNmGU2 Gxyg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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'
Messages sorted by:
Reverse Date,
Date,
Thread,
Author