aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/concommands.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/shared/concommands.lua')
-rw-r--r--gamemode/shared/concommands.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/gamemode/shared/concommands.lua b/gamemode/shared/concommands.lua
new file mode 100644
index 0000000..b4e844a
--- /dev/null
+++ b/gamemode/shared/concommands.lua
@@ -0,0 +1,28 @@
+--[[
+ Various console command helper functions
+]]
+
+local fuzzel = include("fuzzel.lua")
+
+local concmd = {}
+
+function concmd.AutocompleteFunction(...)
+ local opt = {...}
+ opt = type(opt[1]) == "table" and opt[1] or opt
+ return function(cmd,strargs)
+ --Remove spaces and quotes, since we don't want to match them
+ strargs = string.gsub(strargs,"[\" ]","")
+ --Find the options that most closely resemble our command so far
+ local sorted = fuzzel.fad(strargs,opt)
+ --Add quotes if needed, and preppend the command to each option
+ for k,v in pairs(sorted) do
+ if string.find(v," ") ~= nil then
+ sorted[k] = "\"" .. v .. "\""
+ end
+ sorted[k] = cmd .. " " .. sorted[k]
+ end
+ return sorted
+ end
+end
+
+return concmd