mirror of
https://github.com/atuinsh/atuin.git
synced 2025-08-16 01:58:13 +02:00
feat: Add 'atuin scripts rm' and 'atuin scripts ls' aliases; allow reading from stdin (#2680)
* Add 'atuin scripts rm' and 'atuin scripts ls' aliases * Allow creating new scripts from stdin
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::io::IsTerminal;
|
||||||
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use atuin_scripts::execution::template_script;
|
use atuin_scripts::execution::template_script;
|
||||||
@ -107,10 +109,12 @@ pub struct Delete {
|
|||||||
pub enum Cmd {
|
pub enum Cmd {
|
||||||
New(NewScript),
|
New(NewScript),
|
||||||
Run(Run),
|
Run(Run),
|
||||||
|
#[command(alias = "ls")]
|
||||||
List(List),
|
List(List),
|
||||||
|
|
||||||
Get(Get),
|
Get(Get),
|
||||||
Edit(Edit),
|
Edit(Edit),
|
||||||
|
#[command(alias = "rm")]
|
||||||
Delete(Delete),
|
Delete(Delete),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +214,7 @@ impl Cmd {
|
|||||||
script_db: atuin_scripts::database::Database,
|
script_db: atuin_scripts::database::Database,
|
||||||
history_db: &impl Database,
|
history_db: &impl Database,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let mut stdin = std::io::stdin();
|
||||||
let script_content = if let Some(count_opt) = new_script.last {
|
let script_content = if let Some(count_opt) = new_script.last {
|
||||||
// Get the last N commands from history, plus 1 to exclude the command that runs this script
|
// Get the last N commands from history, plus 1 to exclude the command that runs this script
|
||||||
let count = count_opt.unwrap_or(1) + 1; // Add 1 to the count to exclude the current command
|
let count = count_opt.unwrap_or(1) + 1; // Add 1 to the count to exclude the current command
|
||||||
@ -249,6 +254,10 @@ impl Cmd {
|
|||||||
} else if let Some(script_path) = new_script.script {
|
} else if let Some(script_path) = new_script.script {
|
||||||
let script_content = std::fs::read_to_string(script_path)?;
|
let script_content = std::fs::read_to_string(script_path)?;
|
||||||
Some(script_content)
|
Some(script_content)
|
||||||
|
} else if !stdin.is_terminal() {
|
||||||
|
let mut buffer = String::new();
|
||||||
|
stdin.read_to_string(&mut buffer)?;
|
||||||
|
Some(buffer)
|
||||||
} else {
|
} else {
|
||||||
// Open editor with empty file
|
// Open editor with empty file
|
||||||
Some(Self::open_editor(None)?)
|
Some(Self::open_editor(None)?)
|
||||||
|
Reference in New Issue
Block a user