Completions¶
A set of completions for use with kmd.Kmd.
Completion Protocol¶
A custom completion is a class that implements at least two methods:
- Completion.__init__()¶
Initializes the completion and configures the readline completer for the type of completion instantiated. May accept additional arguments.
- Completion.__call__(text)¶
Returns an iterable of matches for
text.
Filename Completion¶
- class kmd.completions.FilenameCompletion(quote_char='\\')¶
Complete file and directory names. The
quote_charargument specifies the preferred quoting style. Available styles are single-quote, double-quote, and backslash (the default).To ensure proper configuration of readline,
FilenameCompletionshould always be instantiated before other completions.
- FilenameCompletion.__call__(text)¶
Return filenames matching
text. Starts at the current working directory.
- FilenameCompletion.char_is_quoted(text, index)¶
Return True if the character at
indexis quoted. Installed asrl.completer.char_is_quoted_function.
- FilenameCompletion.quote_filename(text, single_match, quote_char)¶
Return a quoted version of
text. Installed asrl.completer.filename_quoting_function.
- FilenameCompletion.dequote_filename(text, quote_char)¶
Return a dequoted version of
text. Installed asrl.completer.filename_dequoting_function.
- FilenameCompletion.rewrite_dirname(text)¶
Convert a directory name the user typed to a format suitable for passing to
opendir(). Installed asrl.completer.directory_rewrite_hook.
- FilenameCompletion.rewrite_filename(text)¶
Convert a filename read from the filesystem to a format suitable for comparing against the completion word. Installed as
rl.completer.filename_rewrite_hook.
- FilenameCompletion.stat_filename(text)¶
Convert a filename the user typed to a format suitable for passing to
stat(). Installed asrl.completer.filename_stat_hook.
Username Completion¶
- class kmd.completions.UsernameCompletion¶
Complete user names.
- UsernameCompletion.__call__(text)¶
Return user names matching
text.User names are returned without decoration. The search string may start with a
~character, in which case the users’ home directories are returned instead. Home directories start with a~and end with a/character.
Hostname Completion¶
- class kmd.completions.HostnameCompletion(hostsfile='/etc/hosts')¶
Complete host names found in the system’s hosts file.
- HostnameCompletion.__call__(text)¶
Return host names matching
text.Host names are returned with a leading
@character. The search string may start with an@character which is stripped before matching.
Environment Completion¶
- class kmd.completions.EnvironmentCompletion¶
Complete names of variables in the process environment.
- EnvironmentCompletion.__call__(text)¶
Return environment variables matching
text.Variable names are returned with a leading
$character. The search string may start with a$character which is stripped before matching.
Command Completion¶
- class kmd.completions.CommandCompletion¶
Complete names of commands on the system PATH.
- CommandCompletion.__call__(text)¶
Return executables matching
text. Does not include shell built-ins or aliases.