fish completer support #263
-
Hi, I'm currently trying to implement a completer in Hilbish using the fish shell to generate the completions. This is my current effort: -- Utility for using fish shell completions in Hilbish.
local utils = require ".utils"
local fish_completer = {}
fish_completer.complete_func = function(query, ctx, fields)
-- Run fish
local cmd = "fish --command 'complete \"--do-complete=" .. ctx .. "\"'"
local res = io.popen(cmd)
local raw_str = res:read('*all')
-- Extract completion items
local values = utils.split(raw_str, "\n")
-- Fish completer gives descriptions as well as completions,
-- so just grab the completions
local comp_items = {}
for _, v in pairs(values) do
local _, count = string.gsub(v, " ", "")
if count > 0 then
local split = utils.split(v)
comp_items[#comp_items+1] = split[1]
else
comp_items[#comp_items+1] = v
end
end
local comp = {
{
items = comp_items,
type = 'grid'
}
}
return comp, query
end
return fish_completer
utils.split = function(inputstr, sep)
if sep == nil then
sep = '%s'
end
local t={}
for str in string.gmatch(inputstr, '([^'..sep..']+)') do
table.insert(t, str)
end
return t
end You would use this by doing something like the following: hilbish.complete('command.git', fish_completer.complete_func) This is obviously an incomplete implementation, because quotes would break the command substitution, but I'm just trying to get something basic working first. This does generate the completions as desired, but in instances like when the line to be completed is as follows: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
firstly, some minor things: hilbish actually has a builtin after checking our your code, it can be a little bit more efficient, but i also realized that this is due to a bug it seems? when hilbish gets the prefix, it's |
Beta Was this translation helpful? Give feedback.
firstly, some minor things:
hilbish actually has a builtin
string.split
function, but it is not documented.secondly, there is the
hilbish.run
function which you should be using instead of io.popen (its just better)after checking our your code, it can be a little bit more efficient, but i also realized that this is due to a bug it seems? when hilbish gets the prefix, it's
nil
for some reason.