feat: Implement a two-phase init which allows us to write normal init scripts (#168)

Implement a two-phase init procedure in starship. The first phase causes the shell to source a subshell, while the second phase (in the subshell) prints the main init script.

This allows us to have nice init scripts with good styling, comments, and no pile of semicolons. Even better, it works as a drop-in replacement, so we don't need to update the docs.
This commit is contained in:
Kevin Song
2019-08-19 18:44:53 -07:00
committed by GitHub
parent 2e39c6d0fa
commit 0e82c19f37
2 changed files with 166 additions and 107 deletions
+11 -2
View File
@@ -58,6 +58,10 @@ fn main() {
.help("The number of currently running jobs")
.takes_value(true);
let init_scripts_arg = Arg::with_name("print_full_init")
.long("print-full-init")
.help("Print the main initialization script (as opposed to the init stub)");
let matches = App::new("starship")
.about("The cross-shell prompt for astronauts. ☄🌌️")
// pull the version number from Cargo.toml
@@ -69,7 +73,8 @@ fn main() {
.subcommand(
SubCommand::with_name("init")
.about("Prints the shell function used to execute starship")
.arg(&shell_arg),
.arg(&shell_arg)
.arg(&init_scripts_arg),
)
.subcommand(
SubCommand::with_name("prompt")
@@ -99,7 +104,11 @@ fn main() {
match matches.subcommand() {
("init", Some(sub_m)) => {
let shell_name = sub_m.value_of("shell").expect("Shell name missing.");
init::init(shell_name)
if sub_m.is_present("print_full_init") {
init::init_main(shell_name);
} else {
init::init_stub(shell_name);
}
}
("prompt", Some(sub_m)) => print::prompt(sub_m.clone()),
("module", Some(sub_m)) => {