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:
Barnaby Keene
2019-10-08 14:47:30 +01:00
parent a882e640e4
commit fb8cfeb70d
3 changed files with 186 additions and 17 deletions

View File

@ -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 {