aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichelle Tilley <michelle@michelletilley.net>2025-04-08 06:47:15 -0700
committerGitHub <noreply@github.com>2025-04-08 14:47:15 +0100
commita62d27c5f14da4d48c2da553b3957bc91311a565 (patch)
tree1d5162f2c8a45d0e01b434af39ad03754edb283d
parentchore(release): prepare for release 18.5.0-beta.3 (#2678) (diff)
downloadatuin-a62d27c5f14da4d48c2da553b3957bc91311a565.zip
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
-rw-r--r--crates/atuin/src/command/client/scripts.rs9
1 files changed, 9 insertions, 0 deletions
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)?)