From a62d27c5f14da4d48c2da553b3957bc91311a565 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Tue, 8 Apr 2025 06:47:15 -0700 Subject: [PATCH] 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 --- crates/atuin/src/command/client/scripts.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/atuin/src/command/client/scripts.rs b/crates/atuin/src/command/client/scripts.rs index 3993d6b8..2b4b58bb 100644 --- a/crates/atuin/src/command/client/scripts.rs +++ b/crates/atuin/src/command/client/scripts.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; use std::collections::HashSet; +use std::io::IsTerminal; +use std::io::Read; use std::path::PathBuf; use atuin_scripts::execution::template_script; @@ -107,10 +109,12 @@ pub struct Delete { pub enum Cmd { New(NewScript), Run(Run), + #[command(alias = "ls")] List(List), Get(Get), Edit(Edit), + #[command(alias = "rm")] Delete(Delete), } @@ -210,6 +214,7 @@ impl Cmd { script_db: atuin_scripts::database::Database, history_db: &impl Database, ) -> Result<()> { + let mut stdin = std::io::stdin(); 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 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 { let script_content = std::fs::read_to_string(script_path)?; Some(script_content) + } else if !stdin.is_terminal() { + let mut buffer = String::new(); + stdin.read_to_string(&mut buffer)?; + Some(buffer) } else { // Open editor with empty file Some(Self::open_editor(None)?)