pub struct Hook { /* private fields */ }shell-init only.Expand description
A command of the CLI that the shell runs once, in the foreground, before its first prompt.
It runs as <bin> <subcommand>, and only when the environment variable
variable is set to a non-empty value and bin is on PATH. Each shell
removes the hook before running the command, so a later prompt never runs
it again.
In bash, another tool, such as bash-preexec, can rewrite PROMPT_COMMAND
so that the removal misses. So bash’s hook also sets a variable it checks
first.
Every part is one word the shell reads without quoting, which
Hook::new checks once.
Implementations§
Source§impl Hook
impl Hook
Sourcepub fn script(&self, shell: Shell) -> Script
pub fn script(&self, shell: Shell) -> Script
The script that installs this hook in shell.
bash runs it from PROMPT_COMMAND, as a string or, from bash 5.1, an
array. zsh runs it from precmd_functions, and fish on the
fish_prompt event. The bash hook returns the exit status it found, so
a prompt command after it still reads the status of the user’s last
command.