feat: support arbitrary shell

This commit is contained in:
iff 2024-11-18 22:08:49 +01:00
parent 6ebd624b28
commit 5c8fa52a32

View file

@ -61,19 +61,16 @@ pub fn last_command(shell: &str) -> String {
"zsh" => last_command, "zsh" => last_command,
"fish" => last_command, "fish" => last_command,
"nu" => last_command, "nu" => last_command,
_ => { _ => last_command,
eprintln!("Unsupported shell: {}", shell);
exit(1);
}
} }
} }
pub fn expand_alias(shell: &str, full_command: &str) -> String { pub fn expand_alias(shell: &str, full_command: &str) -> String {
let alias = std::env::var("_PR_ALIAS").expect(&t!( let alias_env = std::env::var("_PR_ALIAS");
"no-env-setup", if alias_env.is_err() {
var = "_PR_ALIAS", return full_command.to_string();
help = "pay-respects -h" }
)); let alias = alias_env.unwrap();
if alias.is_empty() { if alias.is_empty() {
return full_command.to_string(); return full_command.to_string();
} }
@ -184,11 +181,13 @@ pub fn initialization(shell: &str, binary_path: &str, auto_alias: &str) {
}; };
let init = format!( let init = format!(
r#"def --env {} [] {{ r#"
let dir = (with-env {{ _PR_LAST_COMMAND: {}, _PR_ALIAS: {}, _PR_SHELL: nu }} {{ {} }}) def --env {} [] {{
let dir = (with-env {{ _PR_LAST_COMMAND: {}, _PR_SHELL: nu }} {{ {} }})
cd $dir cd $dir
}}"#, }}
pr_alias, last_command, alias, binary_path "#,
pr_alias, last_command, binary_path
); );
println!("{}", init); println!("{}", init);
std::process::exit(0); std::process::exit(0);