diff --git a/example/cmd/_test/cmd-clink.lua b/example/cmd/_test/cmd-clink.lua index e8fd991f..78dfe223 100644 --- a/example/cmd/_test/cmd-clink.lua +++ b/example/cmd/_test/cmd-clink.lua @@ -1,9 +1,13 @@ local function example_completion(word, word_index, line_state, match_builder) args = { "example", "_carapace", "fish", "\"\"" } - for i = 2,word_index,1 do + for i = 2,word_index-1,1 do table.insert(args, string.format("%q" ,line_state:getword(i))) end - -- table.insert(args, word) + + -- table.insert(args, string.format("%q", word)) + local exploded = string.explode(line_state:getline() .. "a") + word = string.gsub(exploded[#exploded], 'a$', "") + table.insert(args, string.format("%q", word)) output = io.popen(table.concat(args, " ")):read("*a") for line in string.gmatch(output, '[^\r\n]+') do diff --git a/internal/shell/cmd_clink/snippet.go b/internal/shell/cmd_clink/snippet.go index 530d7144..6b31692d 100644 --- a/internal/shell/cmd_clink/snippet.go +++ b/internal/shell/cmd_clink/snippet.go @@ -10,10 +10,14 @@ import ( func Snippet(cmd *cobra.Command) string { result := fmt.Sprintf(`local function %v_completion(word, word_index, line_state, match_builder) args = { %#v, "_carapace", "fish", "\"\"" } - for i = 2,word_index,1 do + for i = 2,word_index-1,1 do table.insert(args, string.format("%%q" ,line_state:getword(i))) end - -- table.insert(args, word) + + -- table.insert(args, string.format("%%q", word)) + local exploded = string.explode(line_state:getline() .. "a") + word = string.gsub(exploded[#exploded], 'a$', "") + table.insert(args, string.format("%%q", word)) output = io.popen(table.concat(args, " ")):read("*a") for line in string.gmatch(output, '[^\r\n]+') do