aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-25 20:16:08 +0100
committerStefan Boberg <[email protected]>2026-03-25 20:16:08 +0100
commit52535f478143c1d1aaffdb1ce05eacf2d0fb9a62 (patch)
tree921e5dc402dd8acd0f939885ed0270d3a49323f0
parentimplemented initial support for shell command completion (diff)
downloadzen-sb/complete.tar.xz
zen-sb/complete.zip
add clink auto completionsb/complete
-rw-r--r--src/zen/zen.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 8ef4f21b5..63cd72bc0 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -764,9 +764,47 @@ HandleSetupCompletion(int argc, char** argv)
{
printf("complete -c zen -f -a '(zen complete (math (count (commandline -cop)) - 1) (commandline -cop) 2>/dev/null)'\n");
}
+ else if (Shell == "clink")
+ {
+ // Clink Lua completion script. Save to a file in clink's script
+ // directory, e.g.:
+ // zen setup-completion clink > "%LOCALAPPDATA%\clink\zen.lua"
+ printf(
+ "local zen_generator = clink.generator(40)\n"
+ "\n"
+ "function zen_generator:generate(line_state, builder)\n"
+ " if line_state:getword(1) ~= 'zen' then\n"
+ " return false\n"
+ " end\n"
+ "\n"
+ " local words = {}\n"
+ " for i = 1, line_state:getwordcount() do\n"
+ " table.insert(words, line_state:getword(i))\n"
+ " end\n"
+ "\n"
+ " local cword = line_state:getwordcount() - 1\n"
+ " local cmd = '\"zen\" complete ' .. cword\n"
+ " for _, w in ipairs(words) do\n"
+ " cmd = cmd .. ' \"' .. w:gsub('\"', '\\\\\"') .. '\"'\n"
+ " end\n"
+ " cmd = cmd .. ' 2>nul'\n"
+ "\n"
+ " local f = io.popen(cmd)\n"
+ " if f then\n"
+ " for line in f:lines() do\n"
+ " if line ~= '' then\n"
+ " builder:addmatch(line, 'arg')\n"
+ " end\n"
+ " end\n"
+ " f:close()\n"
+ " end\n"
+ "\n"
+ " return true\n"
+ "end\n");
+ }
else
{
- fprintf(stderr, "Unknown shell: %s (supported: bash, zsh, fish)\n", Shell.c_str());
+ fprintf(stderr, "Unknown shell: %s (supported: bash, zsh, fish, clink)\n", Shell.c_str());
return 1;
}