mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 08:00:08 +01:00
feat: allow matching command-line arguments
This commit is contained in:
parent
e691596af8
commit
b50672267e
3 changed files with 66 additions and 28 deletions
|
|
@ -87,7 +87,7 @@ mod tests {
|
|||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(
|
||||
spans.get(0).unwrap().text,
|
||||
spans.first().unwrap().text,
|
||||
"30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4"
|
||||
);
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().text, "/var/log/nginx.log");
|
||||
assert_eq!(spans.first().unwrap().text, "/var/log/nginx.log");
|
||||
assert_eq!(spans.get(1).unwrap().text, "test/log/nginx-2.log");
|
||||
assert_eq!(spans.get(2).unwrap().text, "folder/.nginx@4df2.log");
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().text, "/tmp/foo/bar_lol");
|
||||
assert_eq!(spans.first().unwrap().text, "/tmp/foo/bar_lol");
|
||||
assert_eq!(spans.get(1).unwrap().text, "/var/log/boot-strap.log");
|
||||
assert_eq!(spans.get(2).unwrap().text, "../log/kern.log");
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(spans.get(0).unwrap().text, "~/.gnu/.config.txt");
|
||||
assert_eq!(spans.first().unwrap().text, "~/.gnu/.config.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -219,7 +219,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 4);
|
||||
assert_eq!(spans.get(0).unwrap().text, "fd70b5695");
|
||||
assert_eq!(spans.first().unwrap().text, "fd70b5695");
|
||||
assert_eq!(spans.get(1).unwrap().text, "5246ddf");
|
||||
assert_eq!(spans.get(2).unwrap().text, "f924213");
|
||||
assert_eq!(
|
||||
|
|
@ -250,8 +250,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "ipv4");
|
||||
assert_eq!(spans.get(0).unwrap().text, "127.0.0.1");
|
||||
assert_eq!(spans.first().unwrap().pattern, "ipv4");
|
||||
assert_eq!(spans.first().unwrap().text, "127.0.0.1");
|
||||
assert_eq!(spans.get(1).unwrap().pattern, "ipv4");
|
||||
assert_eq!(spans.get(1).unwrap().text, "255.255.10.255");
|
||||
assert_eq!(spans.get(2).unwrap().pattern, "ipv4");
|
||||
|
|
@ -280,7 +280,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 4);
|
||||
assert_eq!(spans.get(0).unwrap().text, "fe80::2:202:fe4");
|
||||
assert_eq!(spans.first().unwrap().text, "fe80::2:202:fe4");
|
||||
assert_eq!(
|
||||
spans.get(1).unwrap().text,
|
||||
"2001:67c:670:202:7ba8:5e41:1591:d723"
|
||||
|
|
@ -312,8 +312,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 2);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "markdown-url");
|
||||
assert_eq!(spans.get(0).unwrap().text, "https://github.io?foo=bar");
|
||||
assert_eq!(spans.first().unwrap().pattern, "markdown-url");
|
||||
assert_eq!(spans.first().unwrap().text, "https://github.io?foo=bar");
|
||||
assert_eq!(spans.get(1).unwrap().pattern, "markdown-url");
|
||||
assert_eq!(spans.get(1).unwrap().text, "http://cdn.com/img.jpg");
|
||||
}
|
||||
|
|
@ -344,10 +344,10 @@ mod tests {
|
|||
|
||||
assert_eq!(spans.len(), 6);
|
||||
assert_eq!(
|
||||
spans.get(0).unwrap().text,
|
||||
spans.first().unwrap().text,
|
||||
"https://www.rust-lang.org/tools"
|
||||
);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "url");
|
||||
assert_eq!(spans.first().unwrap().pattern, "url");
|
||||
assert_eq!(spans.get(1).unwrap().text, "https://crates.io");
|
||||
assert_eq!(spans.get(1).unwrap().pattern, "url");
|
||||
assert_eq!(spans.get(2).unwrap().text, "https://github.io?foo=bar");
|
||||
|
|
@ -383,8 +383,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 2);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "email");
|
||||
assert_eq!(spans.get(0).unwrap().text, "first.last+social@example.com");
|
||||
assert_eq!(spans.first().unwrap().pattern, "email");
|
||||
assert_eq!(spans.first().unwrap().text, "first.last+social@example.com");
|
||||
assert_eq!(spans.get(1).unwrap().pattern, "email");
|
||||
assert_eq!(
|
||||
spans.get(1).unwrap().text,
|
||||
|
|
@ -414,8 +414,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "pointer-address");
|
||||
assert_eq!(spans.get(0).unwrap().text, "0xfd70b5695");
|
||||
assert_eq!(spans.first().unwrap().pattern, "pointer-address");
|
||||
assert_eq!(spans.first().unwrap().text, "0xfd70b5695");
|
||||
assert_eq!(spans.get(1).unwrap().pattern, "pointer-address");
|
||||
assert_eq!(spans.get(1).unwrap().text, "0x5246ddf");
|
||||
assert_eq!(spans.get(2).unwrap().pattern, "pointer-address");
|
||||
|
|
@ -444,7 +444,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 4);
|
||||
assert_eq!(spans.get(0).unwrap().text, "#fd7b56");
|
||||
assert_eq!(spans.first().unwrap().text, "#fd7b56");
|
||||
assert_eq!(spans.get(1).unwrap().text, "#FF00FF");
|
||||
assert_eq!(spans.get(2).unwrap().text, "#00fF05");
|
||||
assert_eq!(spans.get(3).unwrap().text, "#abcd00");
|
||||
|
|
@ -473,7 +473,7 @@ mod tests {
|
|||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(
|
||||
spans.get(0).unwrap().text,
|
||||
spans.first().unwrap().text,
|
||||
"QmRdbNSxDJBXmssAc9fvTtux4duptMvfSGiGuq6yHAQVKQ"
|
||||
);
|
||||
}
|
||||
|
|
@ -524,8 +524,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "diff-a");
|
||||
assert_eq!(spans.get(0).unwrap().text, "src/main.rs");
|
||||
assert_eq!(spans.first().unwrap().pattern, "diff-a");
|
||||
assert_eq!(spans.first().unwrap().text, "src/main.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -550,8 +550,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "diff-b");
|
||||
assert_eq!(spans.get(0).unwrap().text, "src/main.rs");
|
||||
assert_eq!(spans.first().unwrap().pattern, "diff-b");
|
||||
assert_eq!(spans.first().unwrap().text, "src/main.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -576,8 +576,8 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 1);
|
||||
assert_eq!(spans.get(0).unwrap().pattern, "datetime");
|
||||
assert_eq!(spans.get(0).unwrap().text, "2021-03-04T12:23:34");
|
||||
assert_eq!(spans.first().unwrap().pattern, "datetime");
|
||||
assert_eq!(spans.first().unwrap().text, "2021-03-04T12:23:34");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -610,11 +610,43 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().text, "first string");
|
||||
assert_eq!(spans.first().unwrap().text, "first string");
|
||||
assert_eq!(spans.get(1).unwrap().text, "second string");
|
||||
assert_eq!(spans.get(2).unwrap().text, "rustc --explain E0223");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_commandline_args() {
|
||||
let buffer =
|
||||
"command --arg arg1 --arg=arg2 --arg arg3-long -x hashes -a -u -l -x others\n'";
|
||||
let lines = buffer.split('\n').collect::<Vec<_>>();
|
||||
|
||||
let use_all_patterns = false;
|
||||
use crate::textbuf::regexes::parse_pattern_name;
|
||||
let named_pat = vec![parse_pattern_name("command-line-args").unwrap()];
|
||||
let custom = vec![];
|
||||
let alphabet = Alphabet("abcd".to_string());
|
||||
let reverse = false;
|
||||
let unique_hint = false;
|
||||
let spans = Model::new(
|
||||
&lines,
|
||||
&alphabet,
|
||||
use_all_patterns,
|
||||
&named_pat,
|
||||
&custom,
|
||||
reverse,
|
||||
unique_hint,
|
||||
)
|
||||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 5);
|
||||
assert_eq!(spans.first().unwrap().text, "arg1");
|
||||
assert_eq!(spans.get(1).unwrap().text, "arg2");
|
||||
assert_eq!(spans.get(2).unwrap().text, "arg3-long");
|
||||
assert_eq!(spans.get(3).unwrap().text, "hashes");
|
||||
assert_eq!(spans.get(4).unwrap().text, "others");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn priority_between_regexes() {
|
||||
let buffer = "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";
|
||||
|
|
@ -640,7 +672,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 9);
|
||||
assert_eq!(spans.get(0).unwrap().text, "http://foo.bar");
|
||||
assert_eq!(spans.first().unwrap().text, "http://foo.bar");
|
||||
assert_eq!(spans.get(1).unwrap().text, "CUSTOM-52463");
|
||||
assert_eq!(spans.get(2).unwrap().text, "ISSUE-123");
|
||||
assert_eq!(spans.get(3).unwrap().text, "/var/fd70b569/9999.log");
|
||||
|
|
@ -682,7 +714,7 @@ mod tests {
|
|||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 2);
|
||||
assert_eq!(spans.get(0).unwrap().text, "http://foo.bar");
|
||||
assert_eq!(spans.first().unwrap().text, "http://foo.bar");
|
||||
assert_eq!(
|
||||
spans.get(1).unwrap().text,
|
||||
"https://crates.io/23456/fd70b569"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] =
|
|||
///
|
||||
/// The email address was obtained at https://www.regular-expressions.info/email.html.
|
||||
/// Some others were obtained from Ferran Basora, the rest is by me.
|
||||
pub(super) const PATTERNS: [(&str, &str); 20] = [
|
||||
pub(super) const PATTERNS: [(&str, &str); 21] = [
|
||||
("markdown-url", r"\[[^]]*\]\(([^)]+)\)"),
|
||||
(
|
||||
"url",
|
||||
|
|
@ -44,6 +44,10 @@ pub(super) const PATTERNS: [(&str, &str); 20] = [
|
|||
("quoted-double", r#""([^"]+)""#),
|
||||
("quoted-backtick", r#"`([^`]+)`"#),
|
||||
("digits", r"([0-9]{4,})"),
|
||||
(
|
||||
"command-line-args",
|
||||
r#"(?:--[a-z][0-9a-z\-_]+|-[a-z])(?: |=)([^-\s\n]\S+)"#,
|
||||
),
|
||||
];
|
||||
|
||||
/// Type-safe string Pattern Name (newtype).
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ setup_pattern_binding () {
|
|||
tmux bind-key -T ${keytable} ${key} new-window -d -n ${window_name} "${BINARY} run --window-name '"${window_name}"' --clipboard-exe ${clipboard_exe} --reverse --unique-hint ${pattern_arg}"
|
||||
}
|
||||
|
||||
# prefix + t + a searches for command-line arguments
|
||||
setup_pattern_binding "a" "--pattern-name command-line-args"
|
||||
# prefix + t + c searches for hex colors #aa00f5
|
||||
setup_pattern_binding "c" "--pattern-name hexcolor"
|
||||
# prefix + t + d searches for dates or datetimes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue