feat: add basic cut-after
This commit is contained in:
1
crates/cut-after/.gitignore
vendored
Normal file
1
crates/cut-after/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
13
crates/cut-after/Cargo.toml
Normal file
13
crates/cut-after/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "cut-after"
|
||||
edition = "2021"
|
||||
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
||||
dotenv.workspace = true
|
40
crates/cut-after/src/main.rs
Normal file
40
crates/cut-after/src/main.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Command {
|
||||
#[arg()]
|
||||
substr: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = Command::parse();
|
||||
tracing::debug!("Starting cli");
|
||||
|
||||
let mut input = String::new();
|
||||
std::io::stdin()
|
||||
.read_to_string(&mut input)
|
||||
.context("failed to read from stdin")?;
|
||||
|
||||
let mut stdout = std::io::stdout();
|
||||
if let Some((before, _)) = input.split_once(&cli.substr) {
|
||||
stdout.write_all(before.as_bytes())?;
|
||||
} else {
|
||||
stdout.write_all(input.as_bytes())?;
|
||||
}
|
||||
stdout.flush()?;
|
||||
|
||||
if input.is_empty() {
|
||||
tracing::info!("no content to put in clipboard");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user