Skip to main content

Hook

Struct Hook 

Source
pub struct Hook { /* private fields */ }
Available on crate feature 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

Source

pub fn new( bin: &str, subcommand: &str, variable: &str, ) -> Result<Self, HookError>

Declare the hook that runs bin subcommand when variable is set.

§Errors

Returns a HookError naming the first part that is not a plain word.

  • bin and subcommand take letters, digits, -, and _, and start with a letter or digit.
  • variable takes letters, digits, and _, and does not start with a digit.
Source

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.

Trait Implementations§

Source§

impl Clone for Hook

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Hook

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Hook

Source§

impl PartialEq for Hook

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Hook

Auto Trait Implementations§

§

impl Forget for Hook

§

impl Freeze for Hook

§

impl RefUnwindSafe for Hook

§

impl Send for Hook

§

impl Sync for Hook

§

impl Unpin for Hook

§

impl UnsafeUnpin for Hook

§

impl UnwindSafe for Hook

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.