mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 08:00:08 +01:00
chore: merge pull request #15 from graelo/feat/cli-args
Add command-line arguments matching
This commit is contained in:
commit
53bdf54724
5 changed files with 79 additions and 39 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
|
@ -167,9 +167,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.156"
|
||||
version = "0.2.158"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
|
||||
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
|
|
@ -227,9 +227,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.36"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
|
@ -280,9 +280,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
version = "0.38.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
|
||||
checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"errno",
|
||||
|
|
@ -315,9 +315,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.74"
|
||||
version = "2.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
|
||||
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -179,9 +179,11 @@ pub fn available_panes() -> Result<Vec<Pane>> {
|
|||
result
|
||||
}
|
||||
|
||||
/// Returns tmux global options as a `HashMap`. The prefix argument is for
|
||||
/// convenience, in order to target only some of our options. For instance,
|
||||
/// `get_options("@copyrat-")` will return a `HashMap` which keys are tmux options names like `@copyrat-command`, and associated values.
|
||||
/// Returns tmux global options as a `HashMap`.
|
||||
///
|
||||
/// The prefix argument is for convenience, in order to target only some of our options. For
|
||||
/// instance, `get_options("@copyrat-")` will return a `HashMap` which keys are tmux options names
|
||||
/// like `@copyrat-command`, and associated values.
|
||||
///
|
||||
/// # Example
|
||||
/// ```get_options("@copyrat-")```
|
||||
|
|
|
|||
|
|
@ -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