mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 12:47:54 +02:00
feat: starship prompt
Kind of touches on #356 by integrating the Starship prompt directly into the shell. Not finished yet and has surfaced a potential bug in rustyline anyway. It depends on https://github.com/starship/starship/pull/509 being merged so the Starship prompt can be used as a library. I could have tackled #356 completely and implemented a full custom prompt feature but I felt this was a simpler approach given that Starship is both written in Rust so shelling out isn't necessary and it already has a bunch of useful features built in. However, I would understand if it would be preferable to just scrap integrating Starship directly and instead implement a custom prompt system which would facilitate simply shelling out to Starship.
This commit is contained in:
26
src/cli.rs
26
src/cli.rs
@ -365,14 +365,26 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
// Redefine Ctrl-D to same command as Ctrl-C
|
||||
rl.bind_sequence(rustyline::KeyPress::Ctrl('D'), rustyline::Cmd::Interrupt);
|
||||
|
||||
let prompt = &format!(
|
||||
"{}{}> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
let prompt = {
|
||||
#[cfg(feature = "starship-prompt")]
|
||||
{
|
||||
&starship::print::get_prompt(starship::context::Context::new_with_dir(
|
||||
clap::ArgMatches::default(),
|
||||
cwd,
|
||||
))
|
||||
}
|
||||
);
|
||||
#[cfg(not(feature = "starship-prompt"))]
|
||||
{
|
||||
&format!(
|
||||
"{}{}> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
let mut initial_command = Some(String::new());
|
||||
let mut readline = Err(ReadlineError::Eof);
|
||||
while let Some(ref cmd) = initial_command {
|
||||
|
Reference in New Issue
Block a user