Add copyf command

This commit is contained in:
Arthur Beck 2025-05-05 07:02:33 -05:00
parent 4d73a9cd7f
commit 7d4da1cbcc
2 changed files with 13 additions and 1 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
arboard = "3.5.0"
clap = { version = "4.5.37", features = ["derive", "env"] }
hostname = "0.4.1"
termion = "4.0.5"

View file

@ -6,7 +6,7 @@ pub const BUILTINS: [(
&str,
fn(args: Vec<String>, unsplit_args: String, state: &mut super::State) -> i32,
&str,
); 11] = [
); 12] = [
("cd", cd, "[dir]"),
("exit", exit, ""),
("echo", echo, "[-e] [text ...]"),
@ -18,6 +18,7 @@ pub const BUILTINS: [(
("set", set, "name=value [name=value ...]"),
("dumpvars", dumpvars, ""),
("unset", unset, "var [var ...]"),
("copyf", copyf, "")
];
/// Change the directory
@ -253,3 +254,13 @@ pub fn unset(args: Vec<String>, _: String, state: &mut super::State) -> i32 {
0
}
/// Copy the focus to the clipboard.
pub fn copyf(_: Vec<String>, _: String, state: &mut super::State) -> i32 {
let mut clipboard = arboard::Clipboard::new().unwrap();
clipboard.set_text(match &state.focus {
super::Focus::Str(s) => s.clone(),
super::Focus::Vec(_) => format!("{}", state.focus)
}).unwrap();
0
}