mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
BREAKING: use environments to get informations
This commit is contained in:
parent
ee7e6886b9
commit
1b7b11bd3f
6 changed files with 128 additions and 67 deletions
38
src/args.rs
Normal file
38
src/args.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
pub fn handle_args() {
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
if args.len() > 1 {
|
||||
let shell = &args[1];
|
||||
let binary_path = &args[0];
|
||||
let last_command;
|
||||
let alias;
|
||||
|
||||
match shell.as_str() {
|
||||
"bash" => {
|
||||
last_command = "$(history 2)";
|
||||
alias = "$(alias)"
|
||||
}
|
||||
"zsh" => {
|
||||
last_command = "$(fc -ln -1)";
|
||||
alias = "$(alias)"
|
||||
}
|
||||
"fish" => {
|
||||
last_command = "$(history | head -n 1)";
|
||||
alias = "$(alias)";
|
||||
}
|
||||
_ => {
|
||||
println!("Unknown shell: {}", shell);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"\
|
||||
_PR_LAST_COMMAND=\"{}\" \
|
||||
_PR_ALIAS=\"{}\" \
|
||||
_PR_SHELL=\"{}\" \
|
||||
\"{}\"",
|
||||
last_command, alias, shell, binary_path
|
||||
);
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue