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 ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
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.