mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-09 16:00:35 +00:00
Add support for markdown urls
This commit is contained in:
parent
84ae7d3f4d
commit
080bc33c62
@ -18,6 +18,7 @@ letter hint to yank the text in your tmux buffer.
|
|||||||
- Colors in hex
|
- Colors in hex
|
||||||
- Numbers ( 4+ digits )
|
- Numbers ( 4+ digits )
|
||||||
- Hex numbers
|
- Hex numbers
|
||||||
|
- Markdown urls
|
||||||
- IP4 addresses
|
- IP4 addresses
|
||||||
- kubernetes resources
|
- kubernetes resources
|
||||||
- UUIDs
|
- UUIDs
|
||||||
|
@ -16,6 +16,8 @@ lorem /var/log/123e4567/999.log lorem /etc/system.conf lorem
|
|||||||
|
|
||||||
cat ▶ cat ▶ cat ▶ cat ▶ cat 30.6.23.42 lorem 135.2.4.4 lorem 235.23.33.34
|
cat ▶ cat ▶ cat ▶ cat ▶ cat 30.6.23.42 lorem 135.2.4.4 lorem 235.23.33.34
|
||||||
|
|
||||||
|
ipsum [fcsonline](https://github.com/fcsonline) lorem
|
||||||
|
|
||||||
path: /var/log/nginx.log[m
|
path: /var/log/nginx.log[m
|
||||||
|
|
||||||
10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34
|
10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34
|
||||||
|
37
src/state.rs
37
src/state.rs
@ -5,7 +5,8 @@ use std::fmt;
|
|||||||
const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
|
const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
|
||||||
[("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
|
[("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
|
||||||
|
|
||||||
const PATTERNS: [(&'static str, &'static str); 10] = [
|
const PATTERNS: [(&'static str, &'static str); 11] = [
|
||||||
|
("markdown_url", r"\[[^]]*\]\(([^)]+)\)"),
|
||||||
(
|
(
|
||||||
"url",
|
"url",
|
||||||
r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ ]+)",
|
r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ ]+)",
|
||||||
@ -261,6 +262,19 @@ mod tests {
|
|||||||
assert_eq!(results.get(2).unwrap().text.clone(), "127.0.0.1");
|
assert_eq!(results.get(2).unwrap().text.clone(), "127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_markdown_urls() {
|
||||||
|
let lines = split("Lorem ipsum [link](https://github.io?foo=bar) ![](http://cdn.com/img.jpg) lorem");
|
||||||
|
let custom = [].to_vec();
|
||||||
|
let results = State::new(&lines, "abcd", &custom).matches(false, false);
|
||||||
|
|
||||||
|
assert_eq!(results.len(), 2);
|
||||||
|
assert_eq!(results.get(0).unwrap().pattern.clone(), "markdown_url");
|
||||||
|
assert_eq!(results.get(0).unwrap().text.clone(), "https://github.io?foo=bar");
|
||||||
|
assert_eq!(results.get(1).unwrap().pattern.clone(), "markdown_url");
|
||||||
|
assert_eq!(results.get(1).unwrap().text.clone(), "http://cdn.com/img.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_urls() {
|
fn match_urls() {
|
||||||
let lines = split("Lorem ipsum https://www.rust-lang.org/tools lorem\n Lorem ipsumhttps://crates.io lorem https://github.io?foo=bar lorem ssh://github.io");
|
let lines = split("Lorem ipsum https://www.rust-lang.org/tools lorem\n Lorem ipsumhttps://crates.io lorem https://github.io?foo=bar lorem ssh://github.io");
|
||||||
@ -334,18 +348,19 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn priority() {
|
fn priority() {
|
||||||
let lines = split("Lorem CUSTOM-52463 lorem ISSUE-123 lorem\nLorem /var/fd70b569/9999.log 52463 lorem\n Lorem 973113 lorem 123e4567-e89b-12d3-a456-426655440000 lorem 8888 lorem\n https://crates.io/23456/fd70b569 lorem");
|
let lines = split("Lorem [link](http://foo.bar) ipsum CUSTOM-52463 lorem ISSUE-123 lorem\nLorem /var/fd70b569/9999.log 52463 lorem\n Lorem 973113 lorem 123e4567-e89b-12d3-a456-426655440000 lorem 8888 lorem\n https://crates.io/23456/fd70b569 lorem");
|
||||||
let custom = ["CUSTOM-[0-9]{4,}", "ISSUE-[0-9]{3}"].to_vec();
|
let custom = ["CUSTOM-[0-9]{4,}", "ISSUE-[0-9]{3}"].to_vec();
|
||||||
let results = State::new(&lines, "abcd", &custom).matches(false, false);
|
let results = State::new(&lines, "abcd", &custom).matches(false, false);
|
||||||
|
|
||||||
assert_eq!(results.len(), 8);
|
assert_eq!(results.len(), 9);
|
||||||
assert_eq!(results.get(0).unwrap().text.clone(), "CUSTOM-52463");
|
assert_eq!(results.get(0).unwrap().text.clone(), "http://foo.bar");
|
||||||
assert_eq!(results.get(1).unwrap().text.clone(), "ISSUE-123");
|
assert_eq!(results.get(1).unwrap().text.clone(), "CUSTOM-52463");
|
||||||
assert_eq!(results.get(2).unwrap().text.clone(), "/var/fd70b569/9999.log");
|
assert_eq!(results.get(2).unwrap().text.clone(), "ISSUE-123");
|
||||||
assert_eq!(results.get(3).unwrap().text.clone(), "52463");
|
assert_eq!(results.get(3).unwrap().text.clone(), "/var/fd70b569/9999.log");
|
||||||
assert_eq!(results.get(4).unwrap().text.clone(), "973113");
|
assert_eq!(results.get(4).unwrap().text.clone(), "52463");
|
||||||
assert_eq!(results.get(5).unwrap().text.clone(), "123e4567-e89b-12d3-a456-426655440000");
|
assert_eq!(results.get(5).unwrap().text.clone(), "973113");
|
||||||
assert_eq!(results.get(6).unwrap().text.clone(), "8888");
|
assert_eq!(results.get(6).unwrap().text.clone(), "123e4567-e89b-12d3-a456-426655440000");
|
||||||
assert_eq!(results.get(7).unwrap().text.clone(), "https://crates.io/23456/fd70b569");
|
assert_eq!(results.get(7).unwrap().text.clone(), "8888");
|
||||||
|
assert_eq!(results.get(8).unwrap().text.clone(), "https://crates.io/23456/fd70b569");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user