mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
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:
+11
-2
@@ -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)) => {
|
||||
|
||||
Reference in New Issue
Block a user