summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-09-26 13:13:36 +0200
committerqkzk <qu3nt1n@gmail.com>2022-09-26 13:13:36 +0200
commitc9bd0d0042702652028431ff3c5e85f8816cbd94 (patch)
treeeaa53d077629cec1faccd9e92fcfe423a7701f9d
parent48cbd0cccaef080afd367a3ccb29c38382879b6c (diff)
flag regex matching files
-rw-r--r--Cargo.lock63
-rw-r--r--Cargo.toml5
-rw-r--r--config.yaml1
-rw-r--r--readme.md7
-rw-r--r--src/config.rs9
-rw-r--r--src/main.rs25
-rw-r--r--stderr.log7
7 files changed, 106 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 118578ad..c647cafe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,15 @@
version = 3
[[package]]
+name = "aho-corasick"
+version = "0.7.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -57,6 +66,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
+name = "dirs"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
+dependencies = [
+ "dirs-sys",
+]
+
+[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -67,6 +85,17 @@ dependencies = [
]
[[package]]
+name = "dirs-sys"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
+dependencies = [
+ "libc",
+ "redox_users",
+ "winapi",
+]
+
+[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -82,7 +111,9 @@ name = "fm"
version = "0.1.0"
dependencies = [
"chrono",
+ "regex",
"serde_yaml",
+ "shellexpand",
"tuikit",
"users",
]
@@ -165,6 +196,12 @@ dependencies = [
]
[[package]]
+name = "memchr"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
+
+[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -249,6 +286,23 @@ dependencies = [
]
[[package]]
+name = "regex"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.6.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
+
+[[package]]
name = "rustversion"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -280,6 +334,15 @@ dependencies = [
]
[[package]]
+name = "shellexpand"
+version = "2.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4"
+dependencies = [
+ "dirs",
+]
+
+[[package]]
name = "syn"
version = "1.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index c19e5a7b..abf48de4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,8 +13,9 @@ name = "fm"
path = "src/lib.rs"
[dependencies]
-users = "0.11.0"
-tuikit = "*"
chrono = "*"
+regex = "1"
serde_yaml = "0.9.13"
shellexpand = "2.1.2"
+tuikit = "*"
+users = "0.11.0"
diff --git a/config.yaml b/config.yaml
index 51566614..e131b9df 100644
--- a/config.yaml
+++ b/config.yaml
@@ -35,3 +35,4 @@ keybindings:
goto: g
flag_all: '*'
reverse_flags: v
+ regex_match: w
diff --git a/readme.md b/readme.md
index 9b00c1c6..2008fe79 100644
--- a/readme.md
+++ b/readme.md
@@ -43,6 +43,9 @@
- [x] '\*' flag all
- [x] v reverse flags
- [x] allow '~' in GOTO mode
+- [x] regex
+ - [x] search
+ - [x] mark multiple files
## TODO
@@ -51,11 +54,9 @@
- [ ] nvim plugin
- https://github.com/KillTheMule/nvim-rs/blob/master/examples/basic.rs
- https://neovim.io/doc/user/api.html
-- [ ] regex
- - [ ] search
- - [ ] mark multiple files
- [ ] installed config file, user config file
- [ ] completion in goto mode, exec mode, searchmode (???)
+- [ ] confirmation for cut/paste, copy/paste, delete
## BUGS
diff --git a/src/config.rs b/src/config.rs
index dae5da11..0a18cfab 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -77,6 +77,7 @@ pub struct Keybindings {
pub goto: char,
pub flag_all: char,
pub reverse_flags: char,
+ pub regex_match: char,
}
impl Keybindings {
@@ -214,6 +215,13 @@ impl Keybindings {
.chars()
.next()
.unwrap_or('v');
+ let regex_match = yaml["regex_match"]
+ .as_str()
+ .map(|s| s.to_string())
+ .unwrap_or_else(|| "w".to_string())
+ .chars()
+ .next()
+ .unwrap_or('w');
Self {
toggle_hidden,
copy_paste,
@@ -234,6 +242,7 @@ impl Keybindings {
goto,
flag_all,
reverse_flags,
+ regex_match,
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 43ebfa2d..fabcd7df 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use std::os::unix::fs::PermissionsExt;
use std::process::Command;
use std::{env, path, process};
+use regex::Regex;
use tuikit::attr::*;
use tuikit::event::{Event, Key};
use tuikit::key::MouseButton;
@@ -68,6 +69,7 @@ o: xdg-open this file
n: NEWFILE
r: RENAME
g: GOTO
+ w: REGEXMATCH
Enter: Execute mode then NORMAL
Esc: NORMAL
";
@@ -155,6 +157,7 @@ enum Mode {
Help,
Search,
Goto,
+ RegexMatch,
}
impl fmt::Debug for Mode {
@@ -169,6 +172,7 @@ impl fmt::Debug for Mode {
Mode::Help => write!(f, ""),
Mode::Search => write!(f, "Search: "),
Mode::Goto => write!(f, "Goto : "),
+ Mode::RegexMatch => write!(f, "Regex : "),
}
}
}
@@ -355,7 +359,8 @@ impl Status {
| Mode::Rename
| Mode::Exec
| Mode::Search
- | Mode::Goto => self.event_text_insertion(c),
+ | Mode::Goto
+ | Mode::RegexMatch => self.event_text_insertion(c),
Mode::Normal => {
if c == self.keybindings.toggle_hidden {
self.event_toggle_hidden()
@@ -389,6 +394,8 @@ impl Status {
self.mode = Mode::Help
} else if c == self.keybindings.search {
self.mode = Mode::Search
+ } else if c == self.keybindings.regex_match {
+ self.mode = Mode::RegexMatch
} else if c == self.keybindings.quit {
std::process::exit(0)
} else if c == self.keybindings.flag_all {
@@ -579,7 +586,8 @@ impl Status {
Mode::Exec => self.exec_exec(),
Mode::Search => self.exec_search(),
Mode::Goto => self.exec_goto(),
- _ => (),
+ Mode::RegexMatch => self.exec_regex(),
+ Mode::Normal | Mode::Help => (),
}
self.col = 0;
@@ -690,6 +698,19 @@ impl Status {
}
}
+ fn exec_regex(&mut self) {
+ let re = Regex::new(&self.input_string).unwrap();
+ if !self.input_string.is_empty() {
+ self.flagged.clear();
+ for file in self.path_content.files.iter() {
+ if re.is_match(file.path.to_str().unwrap()) {
+ self.flagged.insert(file.path.clone());
+ }
+ }
+ }
+ self.input_string.clear();
+ }
+
fn set_height(&mut self, height: usize) {
self.window.height = height;
self.height = height;
diff --git a/stderr.log b/stderr.log
index a1677ea8..d3686028 100644
--- a/stderr.log
+++ b/stderr.log
@@ -1,4 +1,3 @@
-error: failed to create directory `/home/quentin/gclem/dev/rust/fm/target/debug`
-
-Caused by:
- Permission denied (os error 13)
+ Compiling fm v0.1.0 (/home/quentin/gclem/dev/rust/fm)
+ Finished dev [unoptimized + debuginfo] target(s) in 0.75s
+ Running `target/debug/fm`