2019-04-02 05:23:03 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2019-04-09 05:35:14 +02:00
|
|
|
|
2019-06-10 16:56:17 +02:00
|
|
|
mod config;
|
2019-09-30 14:10:35 +02:00
|
|
|
mod configs;
|
2019-04-19 22:57:14 +02:00
|
|
|
mod context;
|
2019-07-03 14:03:02 +02:00
|
|
|
mod init;
|
2019-05-01 22:34:24 +02:00
|
|
|
mod module;
|
2019-04-04 02:14:26 +02:00
|
|
|
mod modules;
|
|
|
|
mod print;
|
2019-04-12 23:49:20 +02:00
|
|
|
mod segment;
|
2019-06-10 16:56:17 +02:00
|
|
|
mod utils;
|
2019-04-04 02:14:26 +02:00
|
|
|
|
2019-08-20 06:42:25 +02:00
|
|
|
use crate::module::ALL_MODULES;
|
2019-07-03 14:03:02 +02:00
|
|
|
use clap::{App, AppSettings, Arg, SubCommand};
|
2019-04-02 06:45:49 +02:00
|
|
|
|
2019-04-02 05:23:03 +02:00
|
|
|
fn main() {
|
2019-05-14 06:43:11 +02:00
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2019-07-02 22:12:53 +02:00
|
|
|
let status_code_arg = Arg::with_name("status_code")
|
|
|
|
.short("s")
|
|
|
|
.long("status")
|
|
|
|
.value_name("STATUS_CODE")
|
|
|
|
.help("The status code of the previously run command")
|
|
|
|
.takes_value(true);
|
|
|
|
|
|
|
|
let path_arg = Arg::with_name("path")
|
|
|
|
.short("p")
|
|
|
|
.long("path")
|
|
|
|
.value_name("PATH")
|
|
|
|
.help("The path that the prompt should render for")
|
|
|
|
.takes_value(true);
|
|
|
|
|
2019-07-03 14:03:02 +02:00
|
|
|
let shell_arg = Arg::with_name("shell")
|
|
|
|
.value_name("SHELL")
|
|
|
|
.help(
|
2019-12-11 21:31:30 +01:00
|
|
|
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion",
|
2019-07-03 14:03:02 +02:00
|
|
|
)
|
|
|
|
.required(true);
|
|
|
|
|
2019-08-08 19:25:30 +02:00
|
|
|
let cmd_duration_arg = Arg::with_name("cmd_duration")
|
|
|
|
.short("d")
|
|
|
|
.long("cmd-duration")
|
|
|
|
.value_name("CMD_DURATION")
|
|
|
|
.help("The execution duration of the last command, in seconds")
|
|
|
|
.takes_value(true);
|
|
|
|
|
2019-08-17 21:33:19 +02:00
|
|
|
let keymap_arg = Arg::with_name("keymap")
|
|
|
|
.short("k")
|
|
|
|
.long("keymap")
|
|
|
|
.value_name("KEYMAP")
|
2019-08-31 09:59:18 +02:00
|
|
|
// fish/zsh only
|
|
|
|
.help("The keymap of fish/zsh")
|
2019-08-17 21:33:19 +02:00
|
|
|
.takes_value(true);
|
|
|
|
|
2019-08-12 19:42:33 +02:00
|
|
|
let jobs_arg = Arg::with_name("jobs")
|
|
|
|
.short("j")
|
|
|
|
.long("jobs")
|
|
|
|
.value_name("JOBS")
|
|
|
|
.help("The number of currently running jobs")
|
|
|
|
.takes_value(true);
|
|
|
|
|
2019-08-20 03:44:53 +02:00
|
|
|
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)");
|
|
|
|
|
2019-07-03 14:03:02 +02:00
|
|
|
let matches = App::new("starship")
|
|
|
|
.about("The cross-shell prompt for astronauts. ☄🌌️")
|
2019-04-02 05:30:53 +02:00
|
|
|
// pull the version number from Cargo.toml
|
|
|
|
.version(crate_version!())
|
|
|
|
// pull the authors from Cargo.toml
|
|
|
|
.author(crate_authors!())
|
2019-07-03 14:03:02 +02:00
|
|
|
.after_help("https://github.com/starship/starship")
|
|
|
|
.setting(AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("init")
|
|
|
|
.about("Prints the shell function used to execute starship")
|
2019-08-20 03:44:53 +02:00
|
|
|
.arg(&shell_arg)
|
|
|
|
.arg(&init_scripts_arg),
|
2019-07-03 14:03:02 +02:00
|
|
|
)
|
2019-06-06 14:18:00 +02:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("prompt")
|
|
|
|
.about("Prints the full starship prompt")
|
2019-07-02 22:12:53 +02:00
|
|
|
.arg(&status_code_arg)
|
2019-08-08 19:25:30 +02:00
|
|
|
.arg(&path_arg)
|
2019-08-12 19:42:33 +02:00
|
|
|
.arg(&cmd_duration_arg)
|
2019-08-17 21:33:19 +02:00
|
|
|
.arg(&keymap_arg)
|
2019-08-12 19:42:33 +02:00
|
|
|
.arg(&jobs_arg),
|
2019-06-06 14:18:00 +02:00
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("module")
|
|
|
|
.about("Prints a specific prompt module")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("name")
|
|
|
|
.help("The name of the module to be printed")
|
2019-08-20 06:42:25 +02:00
|
|
|
.required(true)
|
|
|
|
.required_unless("list"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("list")
|
|
|
|
.short("l")
|
|
|
|
.long("list")
|
|
|
|
.help("List out all supported modules"),
|
2019-06-06 14:18:00 +02:00
|
|
|
)
|
2019-07-02 22:12:53 +02:00
|
|
|
.arg(&status_code_arg)
|
2019-08-08 19:25:30 +02:00
|
|
|
.arg(&path_arg)
|
2019-08-12 19:42:33 +02:00
|
|
|
.arg(&cmd_duration_arg)
|
2019-08-17 21:33:19 +02:00
|
|
|
.arg(&keymap_arg)
|
2019-08-12 19:42:33 +02:00
|
|
|
.arg(&jobs_arg),
|
2019-04-04 04:57:50 +02:00
|
|
|
)
|
2019-04-02 05:30:53 +02:00
|
|
|
.get_matches();
|
2019-04-02 06:45:49 +02:00
|
|
|
|
2019-06-06 14:18:00 +02:00
|
|
|
match matches.subcommand() {
|
2019-07-03 14:03:02 +02:00
|
|
|
("init", Some(sub_m)) => {
|
|
|
|
let shell_name = sub_m.value_of("shell").expect("Shell name missing.");
|
2019-08-20 03:44:53 +02:00
|
|
|
if sub_m.is_present("print_full_init") {
|
2019-08-22 21:57:32 +02:00
|
|
|
init::init_main(shell_name).expect("can't init_main");
|
2019-08-20 03:44:53 +02:00
|
|
|
} else {
|
2019-08-22 21:57:32 +02:00
|
|
|
init::init_stub(shell_name).expect("can't init_stub");
|
2019-08-20 03:44:53 +02:00
|
|
|
}
|
2019-07-03 14:03:02 +02:00
|
|
|
}
|
2019-06-06 14:18:00 +02:00
|
|
|
("prompt", Some(sub_m)) => print::prompt(sub_m.clone()),
|
|
|
|
("module", Some(sub_m)) => {
|
2019-08-20 06:42:25 +02:00
|
|
|
if sub_m.is_present("list") {
|
|
|
|
println!("Supported modules list");
|
|
|
|
println!("----------------------");
|
|
|
|
for modules in ALL_MODULES {
|
|
|
|
println!("{}", modules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(module_name) = sub_m.value_of("name") {
|
|
|
|
print::module(module_name, sub_m.clone());
|
|
|
|
}
|
2019-06-06 14:18:00 +02:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2019-04-02 05:23:03 +02:00
|
|
|
}
|