Implement shell like common string completion.

Fix #785
This commit is contained in:
hrsh7th
2022-02-13 14:34:28 +09:00
parent 7e473b99d3
commit 070c5572ad
10 changed files with 154 additions and 30 deletions

View File

@@ -43,6 +43,17 @@ str.has_prefix = function(text, prefix)
return true
end
---get_common_string
str.get_common_string = function(text1, text2)
local min = math.min(#text1, #text2)
for i = 1, min do
if not char.match(string.byte(text1, i), string.byte(text2, i)) then
return string.sub(text1, 1, i - 1)
end
end
return string.sub(text1, 1, min)
end
---Remove suffix
---@param text string
---@param suffix string