feat: auto add nushell command

This commit is contained in:
iff 2023-07-31 21:12:57 +02:00
parent 8631f3219f
commit c2e2229cb4
2 changed files with 30 additions and 1 deletions

View file

@ -18,6 +18,9 @@ alias f="$(pay_respect <your_shell_here>)"
# for example, using `zsh`:
alias f="$(pay_respect zsh)"
# for `nushell`, the alias can be added automatically with:
pay_respect nushell
```
You can now **press `F` to Pay Respect**!

View file

@ -1,3 +1,5 @@
use std::io::prelude::*;
pub fn handle_args() {
let args = std::env::args().collect::<Vec<String>>();
if args.len() > 1 {
@ -22,13 +24,37 @@ pub fn handle_args() {
"nu" | "nush" | "nushell" => {
last_command = "(history | last).command";
alias = "\"\"";
println!(
let command = format!(
"with-env {{ _PR_LAST_COMMAND : {},\
_PR_ALIAS : {},\
_PR_SHELL : nu }} \
{{ {} }}",
last_command, alias, binary_path
);
println!("{}\n", command);
println!("Add following to your config file? (Y/n)");
let alias = format!("alias f = {}", command);
println!("{}", alias);
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
match input.trim() {
"Y" | "y" | "" => {
let output = std::process::Command::new("nu")
.arg("-c")
.arg("echo $nu.config-path")
.output()
.expect("Failed to execute process");
let config_path= String::from_utf8_lossy(&output.stdout);
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(true)
.open(config_path.trim())
.expect("Failed to open config file");
writeln!(file, "{}", alias).expect("Failed to write to config file");
},
"n" | _ => std::process::exit(0),
};
std::process::exit(0);
}
_ => {