basic/
basic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use shrs::prelude::{StyledBuf, *};
use shrs_cd_tools::{default_prompt, git::Git, DirParsePlugin, DirParseState};

fn prompt_left() -> StyledBuf {
    styled_buf! {
        " > "
    }
}
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));

    styled_buf! {
        project_info,
        git_branch
    }
}

fn main() {
    let myshell = ShellBuilder::default()
        .with_plugin(DirParsePlugin::new())
        .with_prompt(Prompt::from_sides(prompt_left, prompt_right))
        .build()
        .unwrap();

    myshell.run().expect("Error while running shell");
}