mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-13 23:03:55 +01:00
feat: auto add nushell command
This commit is contained in:
parent
8631f3219f
commit
c2e2229cb4
2 changed files with 30 additions and 1 deletions
|
|
@ -18,6 +18,9 @@ alias f="$(pay_respect <your_shell_here>)"
|
||||||
|
|
||||||
# for example, using `zsh`:
|
# for example, using `zsh`:
|
||||||
alias f="$(pay_respect 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**!
|
You can now **press `F` to Pay Respect**!
|
||||||
|
|
||||||
|
|
|
||||||
28
src/args.rs
28
src/args.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
pub fn handle_args() {
|
pub fn handle_args() {
|
||||||
let args = std::env::args().collect::<Vec<String>>();
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
|
|
@ -22,13 +24,37 @@ pub fn handle_args() {
|
||||||
"nu" | "nush" | "nushell" => {
|
"nu" | "nush" | "nushell" => {
|
||||||
last_command = "(history | last).command";
|
last_command = "(history | last).command";
|
||||||
alias = "\"\"";
|
alias = "\"\"";
|
||||||
println!(
|
let command = format!(
|
||||||
"with-env {{ _PR_LAST_COMMAND : {},\
|
"with-env {{ _PR_LAST_COMMAND : {},\
|
||||||
_PR_ALIAS : {},\
|
_PR_ALIAS : {},\
|
||||||
_PR_SHELL : nu }} \
|
_PR_SHELL : nu }} \
|
||||||
{{ {} }}",
|
{{ {} }}",
|
||||||
last_command, alias, binary_path
|
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);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue