feat: match version numbers

This commit is contained in:
graelo 2021-03-17 10:12:57 +01:00
parent 646ee8b9fb
commit 0e0e581f86
4 changed files with 12 additions and 17 deletions

View file

@ -91,6 +91,8 @@ setup_pattern_binding "D" "--pattern-name docker"
setup_pattern_binding "c" "--pattern-name hexcolor"
# prefix + t + U searches for UUIDs
setup_pattern_binding "U" "--pattern-name uuid"
# prefix + t + v searches for version numbers
setup_pattern_binding "v" "--pattern-name version"
# prefix + t + d searches for any string of 4+ digits
setup_pattern_binding "d" "--pattern-name digits"
# prefix + t + m searches for hex numbers: 0xbedead

View file

@ -23,7 +23,7 @@ impl OutputDestination {
impl fmt::Display for OutputDestination {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Tmux => write!(f, "tmux"),
Self::Tmux => write!(f, "tmux buffer"),
Self::Clipboard => write!(f, "clipboard"),
}
}

View file

@ -7,7 +7,7 @@ pub const EXCLUDE_PATTERNS: [(&str, &str); 1] =
///
/// The email address was obtained at https://www.regular-expressions.info/email.html.
/// Others were obtained from Ferran Basora.
pub const PATTERNS: [(&str, &str); 15] = [
pub const PATTERNS: [(&str, &str); 16] = [
("markdown-url", r"\[[^]]*\]\(([^)]+)\)"),
(
"url",
@ -23,6 +23,10 @@ pub const PATTERNS: [(&str, &str); 15] = [
"uuid",
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
),
(
"version",
r"(v?\d{1,4}\.\d{1,4}(\.\d{1,4})?(-(alpha|beta|rc)(\.\d)?)?)[^.0-9s]",
),
("ipfs", r"Qm[0-9a-zA-Z]{44}"),
("sha", r"[0-9a-f]{7,40}"),
("ipv4", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),

View file

@ -33,8 +33,8 @@ struct BridgeOpt {
/// Name of the copy-to-clipboard executable.
///
/// If the output destination is set to keyboard, copyrat will pipe the
/// selected text to this executable.
/// If during execution, the output destination is set to be clipboard,
/// then copyrat will pipe the selected text to this executable.
#[clap(long, default_value = "pbcopy")]
clipboard_exe: String,
@ -94,8 +94,8 @@ fn main() -> Result<(), error::ParseError> {
tmux::swap_pane_with(&temp_pane_spec)?;
// Finally copy selection to a tmux buffer, and paste it to the active
// buffer if it was uppercased.
// Finally copy selection to the output destination (tmux buffer or
// clipboard), and paste it to the active buffer if it was uppercased.
match selection {
None => return Ok(()),
@ -105,25 +105,14 @@ fn main() -> Result<(), error::ParseError> {
output_destination,
}) => {
if uppercased {
// let args = vec!["send-keys", "-t", active_pane.id.as_str(), &text];
// process::execute("tmux", &args)?;
duct::cmd!("tmux", "send-keys", "-t", active_pane.id.as_str(), &text).run()?;
}
match output_destination {
OutputDestination::Tmux => {
// let args = vec!["set-buffer", &text];
// process::execute("tmux", &args)?;
duct::cmd!("tmux", "set-buffer", &text).run()?;
// if uppercased {
// let args = vec!["paste-buffer", "-t", active_pane.id.as_str()];
// process::execute("tmux", &args)?;
// }
}
OutputDestination::Clipboard => {
// let args = [("echo", vec![&text[..]]), ("pbcopy", vec![])];
// process::execute_piped(&args[..])?;
duct::cmd!("echo", "-n", &text)
.pipe(duct::cmd!(opt.clipboard_exe))
.read()?;