View Source Shell.Completion (fnord v0.6.4)

Public API for generating shell completion scripts.

This module defines the DSL types and provides a single function to generate a completion script for a given shell type.

Example

Shell.Completion.generate(spec, shell: :bash)

Summary

Types

Specification for an argument.

Specification for a top-level command.

A source for completions: static choices, command output, files, directories, or a custom function (not supported).

Specification for an option.

Specification for a subcommand.

Functions

Generates a shell completion script for the given spec.

Types

argument_spec()

@type argument_spec() :: %{name: String.t(), from: completion_source()}

Specification for an argument.

command_spec()

@type command_spec() :: %{
  :name => String.t(),
  optional(:description) => String.t(),
  optional(:subcommands) => [subcommand_spec()],
  optional(:arguments) => [argument_spec()],
  optional(:options) => [option_spec()]
}

Specification for a top-level command.

completion_source()

@type completion_source() ::
  {:choices, [String.t()]}
  | {:command, String.t()}
  | :files
  | :directories
  | (String.t() -> [String.t()])

A source for completions: static choices, command output, files, directories, or a custom function (not supported).

option_spec()

@type option_spec() :: %{
  :name => String.t(),
  optional(:from) => completion_source(),
  optional(:takes_argument) => boolean()
}

Specification for an option.

subcommand_spec()

@type subcommand_spec() :: %{
  :name => String.t(),
  optional(:description) => String.t(),
  optional(:arguments) => [argument_spec()],
  optional(:options) => [option_spec()],
  optional(:subcommands) => [subcommand_spec()]
}

Specification for a subcommand.

Functions

generate(spec, list)

@spec generate(
  command_spec(),
  keyword()
) :: String.t()

Generates a shell completion script for the given spec.

Options

  • :shell - The type of shell to generate completions for (currently only :bash and :zsh are supported).

Example

Shell.Completion.generate(spec, shell: :bash)