aboutsummaryrefslogtreecommitdiffstats
path: root/config/yazi/plugins/smart-filter.yazi
diff options
context:
space:
mode:
Diffstat (limited to 'config/yazi/plugins/smart-filter.yazi')
-rw-r--r--config/yazi/plugins/smart-filter.yazi/LICENSE21
-rw-r--r--config/yazi/plugins/smart-filter.yazi/README.md28
-rw-r--r--config/yazi/plugins/smart-filter.yazi/main.lua50
3 files changed, 99 insertions, 0 deletions
diff --git a/config/yazi/plugins/smart-filter.yazi/LICENSE b/config/yazi/plugins/smart-filter.yazi/LICENSE
new file mode 100644
index 00000000..fb5b1d62
--- /dev/null
+++ b/config/yazi/plugins/smart-filter.yazi/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 yazi-rs
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/config/yazi/plugins/smart-filter.yazi/README.md b/config/yazi/plugins/smart-filter.yazi/README.md
new file mode 100644
index 00000000..29653394
--- /dev/null
+++ b/config/yazi/plugins/smart-filter.yazi/README.md
@@ -0,0 +1,28 @@
+# smart-filter.yazi
+
+A Yazi plugin that makes filters smarter: continuous filtering, automatically enter unique directory, open file on submitting.
+
+https://github.com/yazi-rs/plugins/assets/17523360/72aaf117-1378-4f7e-93ba-d425a79deac5
+
+## Installation
+
+```sh
+ya pkg add yazi-rs/plugins:smart-filter
+```
+
+## Usage
+
+Add this to your `~/.config/yazi/keymap.toml`:
+
+```toml
+[[mgr.prepend_keymap]]
+on = "F"
+run = "plugin smart-filter"
+desc = "Smart filter"
+```
+
+Note that, the keybindings above are just examples, please tune them up as needed to ensure they don't conflict with your other actions/plugins.
+
+## License
+
+This plugin is MIT-licensed. For more information check the [LICENSE](LICENSE) file.
diff --git a/config/yazi/plugins/smart-filter.yazi/main.lua b/config/yazi/plugins/smart-filter.yazi/main.lua
new file mode 100644
index 00000000..2d1c3cde
--- /dev/null
+++ b/config/yazi/plugins/smart-filter.yazi/main.lua
@@ -0,0 +1,50 @@
+--- @since 25.12.29
+
+local hovered = ya.sync(function()
+ local h = cx.active.current.hovered
+ if not h then
+ return {}
+ end
+
+ return {
+ url = h.url,
+ is_dir = h.cha.is_dir,
+ unique = #cx.active.current.files == 1,
+ }
+end)
+
+local function prompt()
+ return ya.input {
+ title = "Smart filter:",
+ pos = { "center", w = 50 },
+ realtime = true,
+ debounce = 0.1,
+ }
+end
+
+local function entry()
+ local input = prompt()
+
+ while true do
+ local value, event = input:recv()
+ if event ~= 1 and event ~= 3 then
+ ya.emit("escape", { filter = true })
+ break
+ end
+
+ ya.emit("filter_do", { value, smart = true })
+
+ local h = hovered()
+ if h.unique and h.is_dir then
+ ya.emit("escape", { filter = true })
+ ya.emit("enter", {})
+ input = prompt()
+ elseif event == 1 then
+ ya.emit("escape", { filter = true })
+ ya.emit(h.is_dir and "enter" or "open", { h.url })
+ break
+ end
+ end
+end
+
+return { entry = entry }
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage