diff --git a/README.md b/README.md index 465c671..725d75e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ alias f="$(pay_respect )" # 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**! diff --git a/src/args.rs b/src/args.rs index a85be7a..d94c9c2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,3 +1,5 @@ +use std::io::prelude::*; + pub fn handle_args() { let args = std::env::args().collect::>(); 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); } _ => {