-
Notifications
You must be signed in to change notification settings - Fork 7
/
noclink.lua
50 lines (45 loc) · 1.6 KB
/
noclink.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- This is a companion Lua script for the 'noclink.cmd' script.
-- Run 'noclink -?' for more information.
local envname = "NOCLINK_DISABLE_PROMPT_FILTERS"
-- Register a prompt filter that can disable prompt filtering.
local noclink = clink.promptfilter(-999999999)
function noclink:filter(prompt) -- luacheck: no unused
if os.getenv(envname) then
return prompt, false
end
end
-- Helper function to get the path to this Lua script file.
local function get_script_dir()
local dir
local info = debug.getinfo(1, "S")
if info and info.source then
dir = path.getdirectory(info.source:sub(2))
end
return dir or ""
end
-- Set a doskey alias for 'noclink' to run noclink.cmd located in the same
-- directory as this Lua script file.
local alias = os.getalias("noclink")
local dir = get_script_dir()
local command = string.format('"%s" $*', path.join(dir, "noclink.cmd"))
if not alias or (alias:find("noclink.cmd") and alias ~= command) then
if os.setalias then
os.setalias("noclink", command)
else
os.execute("2>nul 1>nul doskey.exe noclink="..command)
end
end
-- Register an argmatcher for 'noclink'.
local argmatcher = clink.argmatcher("noclink")
:addarg("prompt", "noprompt")
:addflags("/?", "-?", "/h", "-h", "/help", "-help", "--help")
if argmatcher.hideflags then
argmatcher:hideflags("/?", "/h", "-h", "/help", "-help", "--help")
end
if argmatcher.adddescriptions then
argmatcher:adddescriptions({
["prompt"] = "Re-enable Clink prompt filtering",
["noprompt"] = "Disable Clink prompt filtering",
["-?"] = "Show help",
})
end