mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Implement simplified prompt setup process (#90)
• Add starship init which prints the shell function used to execute starship • Document the new setup process using starship init • Remove benchmarks for now (WIP replacement benchmarks in "benchmarking" branch )
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
pub fn init(shell_name: &str) {
|
||||
log::debug!("Shell name: {}", shell_name);
|
||||
let setup_script = match shell_name {
|
||||
"bash" => {
|
||||
let script = "PS1=\"$(starship prompt --status=$?)\"";
|
||||
Some(script)
|
||||
}
|
||||
"zsh" => {
|
||||
let script = "PROMPT=\"$(starship prompt --status=$?)\"";
|
||||
Some(script)
|
||||
}
|
||||
"fish" => {
|
||||
let script = "function fish_prompt; starship prompt --status=$status; end";
|
||||
Some(script)
|
||||
}
|
||||
_ => {
|
||||
println!(
|
||||
"printf \"\\n{0} is not yet supported by starship.\\n\
|
||||
For the time being, we support bash, zsh, and fish.\\n\
|
||||
Please open an issue in the starship repo if you would like to \
|
||||
see support for {0}:\\nhttps://github.com/starship/starship/issues/new\"\\n\\n",
|
||||
shell_name
|
||||
);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
if setup_script.is_some() {
|
||||
let script = setup_script.unwrap();
|
||||
print!("{}", script);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Shell {
|
||||
Bash,
|
||||
Fish,
|
||||
Zsh,
|
||||
Unsupported(String),
|
||||
}
|
||||
+22
-4
@@ -3,13 +3,14 @@ extern crate clap;
|
||||
|
||||
mod config;
|
||||
mod context;
|
||||
mod init;
|
||||
mod module;
|
||||
mod modules;
|
||||
mod print;
|
||||
mod segment;
|
||||
mod utils;
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use clap::{App, AppSettings, Arg, SubCommand};
|
||||
|
||||
fn main() {
|
||||
pretty_env_logger::init();
|
||||
@@ -28,13 +29,26 @@ fn main() {
|
||||
.help("The path that the prompt should render for")
|
||||
.takes_value(true);
|
||||
|
||||
let matches = App::new("Starship")
|
||||
.about("The cross-shell prompt for astronauts. ✨🚀")
|
||||
let shell_arg = Arg::with_name("shell")
|
||||
.value_name("SHELL")
|
||||
.help(
|
||||
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish",
|
||||
)
|
||||
.required(true);
|
||||
|
||||
let matches = App::new("starship")
|
||||
.about("The cross-shell prompt for astronauts. ☄🌌️")
|
||||
// pull the version number from Cargo.toml
|
||||
.version(crate_version!())
|
||||
// pull the authors from Cargo.toml
|
||||
.author(crate_authors!())
|
||||
.after_help("https://github.com/matchai/starship")
|
||||
.after_help("https://github.com/starship/starship")
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand(
|
||||
SubCommand::with_name("init")
|
||||
.about("Prints the shell function used to execute starship")
|
||||
.arg(&shell_arg),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("prompt")
|
||||
.about("Prints the full starship prompt")
|
||||
@@ -55,6 +69,10 @@ fn main() {
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
("init", Some(sub_m)) => {
|
||||
let shell_name = sub_m.value_of("shell").expect("Shell name missing.");
|
||||
init::init(shell_name)
|
||||
}
|
||||
("prompt", Some(sub_m)) => print::prompt(sub_m.clone()),
|
||||
("module", Some(sub_m)) => {
|
||||
let module_name = sub_m.value_of("name").expect("Module name missing.");
|
||||
|
||||
Reference in New Issue
Block a user