mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Zsh completions: use #compdef <program>
This means zsh scripts can't be sourced, but they can be automatically loaded from files which is the standard way of doing it.
This commit is contained in:
@@ -86,7 +86,7 @@ complete -F _comptest -o bashdefault -o default comptest
|
|||||||
|
|
||||||
it("generates correct zsh completion script", function()
|
it("generates correct zsh completion script", function()
|
||||||
assert.equal([=[
|
assert.equal([=[
|
||||||
compdef _comptest comptest
|
#compdef comptest
|
||||||
|
|
||||||
_comptest() {
|
_comptest() {
|
||||||
local context state state_descr line
|
local context state state_descr line
|
||||||
@@ -179,6 +179,8 @@ _comptest_admin_cmds() {
|
|||||||
)
|
)
|
||||||
_describe "command" commands
|
_describe "command" commands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_comptest
|
||||||
]=], get_output("completion zsh"))
|
]=], get_output("completion zsh"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@@ -1409,7 +1409,7 @@ end
|
|||||||
function Parser:get_zsh_complete()
|
function Parser:get_zsh_complete()
|
||||||
self._basename = base_name(self._name)
|
self._basename = base_name(self._name)
|
||||||
assert(self:_is_shell_safe())
|
assert(self:_is_shell_safe())
|
||||||
local buf = {("compdef _%s %s\n"):format(self._basename, self._basename)}
|
local buf = {("#compdef %s\n"):format(self._basename)}
|
||||||
local cmds_buf = {}
|
local cmds_buf = {}
|
||||||
table.insert(buf, "_" .. self._basename .. "() {")
|
table.insert(buf, "_" .. self._basename .. "() {")
|
||||||
if #self._commands > 0 then
|
if #self._commands > 0 then
|
||||||
@@ -1425,7 +1425,7 @@ function Parser:get_zsh_complete()
|
|||||||
if #cmds_buf > 0 then
|
if #cmds_buf > 0 then
|
||||||
result = result .. "\n" .. table.concat(cmds_buf, "\n")
|
result = result .. "\n" .. table.concat(cmds_buf, "\n")
|
||||||
end
|
end
|
||||||
return result .. "\n"
|
return result .. "\n\n_" .. self._basename .. "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fish_escape(string)
|
local function fish_escape(string)
|
||||||
|
Reference in New Issue
Block a user