Shells¶
- class django_typer.shells.DjangoTyperShellCompleter(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
An extension to the click shell completion classes that provides a Django specific shell completion implementation. If you wish to support a new shell, you must derive from this class, implement all of the abstract methods, and register the class with
register_completion_class()
- Parameters:
cli (Command | None) – The click command object to complete
ctx_args (MutableMapping[str, Any]) – Additional context arguments to pass to the typer/click context of the management command being completed
prog_name (str) – The name of the command to complete
complete_var (str) – The name of the environment variable to pass the completion string (unused)
command (ShellCompletion | None) – The Django shellcompletion command
command_str (str | None) – The command string to complete
command_args (List[str] | None) – The command arguments to complete
template (str | None) – The name of the shell completion script template
color (bool | None) – Allow or disallow color and formatting in the completion output
color_default (bool)
- __init__(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
- get_completions(args, incomplete)[source]¶
Get the completions for the current command string and incomplete string.
- Parameters:
- Return type:
- abstractmethod get_user_profile()[source]¶
Most shells have a profile script that is sourced when the interactive shell starts. Deriving classes should implement this method to return the location of that script.
- Return type:
- abstractmethod install(prompt=True)[source]¶
Deriving classes must implement this method to install the completion script.
This method should return the path to the installed script.
- load_template()[source]¶
Return a compiled Template object for the completion script template.
- Return type:
Template | Template
- process_rich_text(text)[source]¶
Removes rich text markup from a string if color is disabled, otherwise it will render the rich markup to ansi control codes. If rich is not installed, none of this happens and the markup will be passed through as is.
- prompt(source, file, prompt=True, start_line=0)[source]¶
Prompt the user for confirmation before editing the file with the given source edits.
- Parameters:
- Returns:
True if the user confirmed the edit, False otherwise.
- Return type:
- source_vars()[source]¶
This returns the context that will be used to render the completion script template.
From the base class we inherit the following variables:
complete_func: the name to use for the shell’s completion function
- complete_var: unused because we do not use environment variables
to pass the completion string
prog_name: the name of the command to complete
We add the following variables:
manage_script: the manage script object - will be either a string or a Path, if it is a Path it will be absolute and this indicates that the script is not installed on the path
manage_script_name: the name of the Django manage script
python: the path to the python interpreter that is running the shellcompletion command
django_command: the name of the Django shellcompletion command - you may change this to something other than ‘shellcompletion’ to provide custom complete logic
color: the color flag to pass to shellcompletion i.e. –(force|no)-color
fallback: the fallback option to pass to
shellcompletion complete
is_installed: whether or not the manage script is a command on the path
shell: the name of the shell
- django_typer.shells.register_completion_class(cls)[source]¶
Register a shell completion class for use with the Django shellcompletion command.
- Parameters:
cls (Type[DjangoTyperShellCompleter])
- Return type:
None
- class django_typer.shells.bash.BashComplete(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
This completer class supports the bash shell. Completion scripts are installed in the
~/.bash_completions
directory and are sourced in~/.bashrc
.Bash does not support help text in completions so these are not returned. The format of the completion is
type,value
and different suggestions are separated by newlines.See also: https://github.com/scop/bash-completion#faq
- Parameters:
- class django_typer.shells.zsh.ZshComplete(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
This completer class supports Zsh. Completion scripts are installed to the
.zfunc
directory in the user’s home directory. Style and completion initialization instructions are added to the user’s.zshrc
file if needed.Returned suggestions are delimited by newlines. Each suggestion is on three lines:
The first line is the type of the completion.
The second line is the value of the completion.
The third line is the help text for the completion.
See also: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
- Parameters:
- class django_typer.shells.powershell.PowerShellComplete(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
This completer class supports the PowerShell versions < 6. See
PwshComplete
for versions >= 6.Completion scripts are installed into the user’s profile file.
Returned suggestions are delimited by
:::
. Each suggestion is one one line.- Parameters:
- color: bool = False¶
PowerShell does support ansi control codes in completion suggestions, but we disable them by default.
- class django_typer.shells.powershell.PwshComplete(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
This completer class supports the PowerShell versions >= 6. See
PowerShellComplete
for versions < 6.All behaviors are the same as
PowerShellComplete
, except thatpwsh
is used instead ofpowershell
.- Parameters:
- color: bool = False¶
PowerShell does support ansi control codes in completion suggestions, but we disable them by default.
- class django_typer.shells.fish.FishComplete(cli=None, ctx_args={}, prog_name='', complete_var='', command=None, command_str=None, command_args=None, template=None, color=None, color_default=True, **kwargs)[source]¶
This completer class supports the fish shell. Completion scripts are installed in the
~/.config/fish/completions
directory.Returned suggestions are formatted as
type,value[ help]
. Each suggestion is on one line and if no help is provided, the help text including the tab delimiter is omitted.- Parameters: