MrPicklePinosaur / shrs

The rusty shell toolkit for hackers
https://mrpicklepinosaur.github.io/shrs/
Apache License 2.0
301 stars 24 forks source link

[Plugin]: shrs_cd_tools inject module specific metadata directly to state #477

Open MrPicklePinosaur opened 3 months ago

MrPicklePinosaur commented 3 months ago

The current usage of cd_tools is to first query from the DirParseState, and then extract the module you desire.

fn prompt_right(state: State<DirParseState>, sh: &Shell) -> StyledBuf {
    let project_info = default_prompt(&state, sh);

    let git_branch = state
        .get_module_metadata::<Git>("git")
        .map(|git| format!("git:{}", git.branch));

   ...
}

There is no reason why we can't just inject Git state directly into shell State and query using

fn prompt_right(git_state: State<Git>, sh: &Shell) -> StyledBuf {
    let git_branch = format!("git:{}", git_state.branch);
   ...
}