From 094475faabb4e2d1d2410e49de52b5211e858e95 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Sun, 17 Nov 2019 17:44:08 +0000 Subject: [PATCH] Add support for IPFS CIDs --- README.md | 1 + src/state.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dcdbd3c..7a05356 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ letter hint to yank the text in your tmux buffer. - File paths - File in diff - Git SHAs +- IPFS CID's - Colors in hex - Numbers ( 4+ digits ) - Hex numbers diff --git a/src/state.rs b/src/state.rs index a1c060c..dacbda9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,7 +5,7 @@ use std::fmt; const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] = [("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; -const PATTERNS: [(&'static str, &'static str); 12] = [ +const PATTERNS: [(&'static str, &'static str); 13] = [ ("markdown_url", r"\[[^]]*\]\(([^)]+)\)"), ( "url", @@ -19,6 +19,7 @@ const PATTERNS: [(&'static str, &'static str); 12] = [ "uid", r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", ), + ("ipfs", r"Qm[0-9a-zA-Z]{44}"), ("sha", r"[0-9a-f]{7,40}"), ("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"), ("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"), @@ -363,6 +364,19 @@ mod tests { assert_eq!(results.get(3).unwrap().text.clone(), "#abcd00"); } + #[test] + fn match_ipfs() { + let lines = split("Lorem QmRdbNSxDJBXmssAc9fvTtux4duptMvfSGiGuq6yHAQVKQ lorem Qmfoobar"); + let custom = [].to_vec(); + let results = State::new(&lines, "abcd", &custom).matches(false, false); + + assert_eq!(results.len(), 1); + assert_eq!( + results.get(0).unwrap().text.clone(), + "QmRdbNSxDJBXmssAc9fvTtux4duptMvfSGiGuq6yHAQVKQ" + ); + } + #[test] fn match_process_port() { let lines = split("Lorem 5695 52463 lorem\n Lorem 973113 lorem 99999 lorem 8888 lorem\n 23456 lorem 5432 lorem 23444");