From 6d7c92fd0ceefee62f5dd70877daa08a8fbcaa54 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 20 Aug 2024 10:44:47 +0100 Subject: [PATCH] wip --- overlays/pkgs/sway-helper/Cargo.lock | 39 +++++++++++++++++++ overlays/pkgs/sway-helper/Cargo.toml | 1 + .../pkgs/sway-helper/src/commands/combi.rs | 23 ++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/overlays/pkgs/sway-helper/Cargo.lock b/overlays/pkgs/sway-helper/Cargo.lock index 04ade35..ab32ee9 100644 --- a/overlays/pkgs/sway-helper/Cargo.lock +++ b/overlays/pkgs/sway-helper/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.15" @@ -313,6 +322,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "rustix" version = "0.38.34" @@ -384,6 +422,7 @@ dependencies = [ "colored", "edit", "fzf-wrapped", + "regex", "swayipc", ] diff --git a/overlays/pkgs/sway-helper/Cargo.toml b/overlays/pkgs/sway-helper/Cargo.toml index a52297e..d9beca8 100644 --- a/overlays/pkgs/sway-helper/Cargo.toml +++ b/overlays/pkgs/sway-helper/Cargo.toml @@ -8,4 +8,5 @@ clap = { version = "4.5.16", features = ["derive"] } colored = "2.1.0" edit = "0.1.5" fzf-wrapped = "0.1.4" +regex = "1.10.6" swayipc = "3.0.2" diff --git a/overlays/pkgs/sway-helper/src/commands/combi.rs b/overlays/pkgs/sway-helper/src/commands/combi.rs index 7db9d7c..18511fd 100644 --- a/overlays/pkgs/sway-helper/src/commands/combi.rs +++ b/overlays/pkgs/sway-helper/src/commands/combi.rs @@ -1,6 +1,7 @@ use super::CliRun; use crate::helpers::programs::list_programs_from_path; use colored::Colorize; +use regex::Regex; pub(crate) struct Combi {} @@ -38,11 +39,21 @@ impl CliRun for Combi { // Fuzzy select something. let selected = crate::helpers::run_fzf("combi", options); - // TODO - let mut s = selected.splitn(2, ' '); - let a = s.next().unwrap(); - println!("{a}"); - let b = s.next().unwrap(); - println!("{b}"); + let re = Regex::new(r"\[(.+)\] (.+)$").unwrap(); + + let caps = re.captures(&selected).unwrap(); + let (a, b) = (&caps[1], &caps[2]); + + match a { + CMD => { + println!("do cmd"); + println!("{b}"); + }, + RUN => { + println!("do run"); + println!("{b}"); + }, + _ => panic!(), + } } }