Hilbish/docs/api/hilbish/hilbish.completion.md

3.7 KiB

title description layout menu
Module hilbish.completion tab completions doc
docs
parent
API

Introduction

The completions interface deals with tab completions.

Functions

bins(query, ctx, fields) -> entries (table), prefix (string) Return binaries/executables based on the provided parameters.
call(name, query, ctx, fields) -> completionGroups (table), prefix (string) Calls a completer function. This is mainly used to call a command completer, which will have a name
files(query, ctx, fields) -> entries (table), prefix (string) Returns file matches based on the provided parameters.
handler(line, pos) This function contains the general completion handler for Hilbish. This function handles

hilbish.completion.bins(query, ctx, fields) -> entries (table), prefix (string)

Return binaries/executables based on the provided parameters.
This function is meant to be used as a helper in a command completion handler.

Parameters

string query

string ctx

table fields

Example

-- an extremely simple completer for sudo.
hilbish.complete('command.sudo', function(query, ctx, fields)
	table.remove(fields, 1)
	if #fields[1] then
		-- return commands because sudo runs a command as root..!

		local entries, pfx = hilbish.completion.bins(query, ctx, fields)
		return {
			type = 'grid',
			items = entries
		}, pfx
	end

	-- ... else suggest files or anything else ..
end)

hilbish.completion.call(name, query, ctx, fields) -> completionGroups (table), prefix (string)

Calls a completer function. This is mainly used to call a command completer, which will have a name
in the form of command.name, example: command.git.
You can check the Completions doc or doc completions for info on the completionGroups return value.

Parameters

string name

string query

string ctx

table fields


hilbish.completion.files(query, ctx, fields) -> entries (table), prefix (string)

Returns file matches based on the provided parameters.
This function is meant to be used as a helper in a command completion handler.

Parameters

string query

string ctx

table fields


hilbish.completion.handler(line, pos)

This function contains the general completion handler for Hilbish. This function handles
completion of everything, which includes calling other command handlers, binaries, and files.
This function can be overriden to supply a custom handler. Note that alias resolution is required to be done in this function.

Parameters

string line
The current Hilbish command line

number pos
Numerical position of the cursor

Example

-- stripped down version of the default implementation
function hilbish.completion.handler(line, pos)
	local query = fields[#fields]

	if #fields == 1 then
		-- call bins handler here
	else
		-- call command completer or files completer here
	end
end