cmdline

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cmdline works out what a terminal offers to complete a command line typed at a shell's prompt with: the rest of a command the shell ran before, and the entries of a folder for the path being typed. It keeps nothing: the commands and the folders come from the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(word, cwd, home string) (dir, base string, ok bool)

Dir is the folder to list for the path word and the start of the name typed there (base): what is before its last slash, from cwd or, after ~/, home. ok is false when the folder cannot be told: a word with a variable, or one relative to a directory not known ("" cwd or home).

func Insert

func Insert(name, base string, dir bool, quote byte) (string, bool)

Insert is what to type after base, the start of name already typed in quote ('\”, '"' or 0), to complete name: the rest of it as the shell reads it there, and a slash after a folder's. ok is false when name does not start with base, or holds what cannot be typed.

func LooksLikePrompt

func LooksLikePrompt(prompt string) bool

LooksLikePrompt reports text that ends as a shell's prompt does, in $, #, %, > or one of the arrows themes draw, a space or none after it: for a terminal whose shell gives no other sign of reading a line. The prompts of Python's and other interpreters' (>>> and ...) do not.

func Suggest

func Suggest(input string, sources ...[]string) string

Suggest is the rest of the first command of sources, taken in order, that starts with input and goes on past it, "" for none. Only a command of one line that can be typed as it is qualifies (Typeable), and input must hold more than blanks.

func Typeable

func Typeable(s string) bool

Typeable reports text that typing sends as it is: valid UTF-8 without control characters, of which a tab would complete and a newline run.

Types

type Arg

type Arg struct {
	// Cmd is the command of the word's simple command: its first word
	// after any assignments and the commands that run another (sudo,
	// env, time…) with their options; "" while it is that word.
	Cmd string
	// Word is the word, its quotes and backslashes undone; Quote the quote
	// it is still open in, '\” or '"', 0 for none.
	Word  string
	Quote byte
	// Index is the word's place in its command, 0 for the first.
	Index int
	// Redirect is set for the word after <, > or >>, a file.
	Redirect bool
	// Start is where the word starts in the line, in bytes.
	Start int
}

Arg is the word being typed at the end of a command line, as a shell splits the line.

func Last

func Last(line string) Arg

Last is the word at the end of line, which is what is typed before the cursor; the word is "" when line ends in a blank.

func (Arg) Path

func (a Arg) Path() (ok, dirs bool)

Path says whether the word of a names a path to complete, and whether a folder alone does there (dirs): a word after cd and the like, or the commands that take files, a redirect's, and any word other than an option holding a slash or starting with ~/, ./ or ../. A command being typed is one only as a path, ./run.

type Entry

type Entry struct {
	Name string
	Dir  bool
}

Entry is a name a folder holds, and whether it is a folder.

func Matches

func Matches(es []Entry, base string, dirs bool) []Entry

Matches are the entries whose name starts with base: folders alone for dirs, names starting with a dot only when base does, never . and ..; folders first, then by name without regard to case.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL