Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide recycle bin, or user defined folders #52

Closed
stax76 opened this issue May 8, 2022 · 5 comments
Closed

Hide recycle bin, or user defined folders #52

stax76 opened this issue May 8, 2022 · 5 comments
Labels
use-addons request should be completed with an addon

Comments

@stax76
Copy link

stax76 commented May 8, 2022

I would like to request hiding the recycle bin:

E:\$RECYCLE.BIN

@CogentRedTester CogentRedTester added the use-addons request should be completed with an addon label May 9, 2022
@CogentRedTester
Copy link
Owner

CogentRedTester commented May 9, 2022

A simple addon like this should work:

local fb_utils = require 'modules.utils'
local valid_dir = fb_utils.valid_dir

fb_utils.valid_dir = function(name)
    if name == "$RECYCLE.BIN/" then return false end
    return valid_dir(name)
end

return { version = "1.1.0" }

Edit: updated with the version number for future compatibility

Edit: updated 2024-01-08 to work with new file-browser internal changes (#100)

@stax76
Copy link
Author

stax76 commented May 9, 2022

Thanks, it works.

Maybe also add a conf option excluded-directories, which is a list of absolute paths.

@stax76 stax76 changed the title Hide recycle bin Hide recycle bin, or user defined folders May 9, 2022
@CogentRedTester
Copy link
Owner

I'd rather something like that be implemented as an addon. The whole reason I designed the addon system was to avoid feature creep bloating the main script. I might look into it when I have some free time, but if you really want it you're welcome to write the addon yourself. I recently updated the documentation with code examples, which might make it easier to understand. You're also welcome to ask any questions.

@CogentRedTester
Copy link
Owner

CogentRedTester commented May 10, 2022

To give a bit of an idea, something along these lines would probably work:

local fb = require "file-browser"

local parser = {
    priority = 10,
    version = "1.1.0"
}

local function filter(path)
    -- do filtering here
end

function parser:can_parse()
    return true
end

function parser:parse(directory)
    local list, opts = self:defer(directory)
    if not list then return list, opts end

    directory = opts.directory or directory

    for i=#list, 1, -1 do
        if filter( fb.get_full_path(list[i], directory) ) then
            table.remove(list, i)
        end
   end

    return list, opts
end

return parser

Disclaimer: I wrote this very quickly from memory and have done no testing whatsoever

@CogentRedTester
Copy link
Owner

I had some time so here is a full implementation of an addon that allows you to filter any arbitrary path by changing a config file:

local fb = require "file-browser"
local opt = require "mp.options"

local o = {
    --list of absolute paths separated by the root separators
    paths = ""
}

--config file stored in ~~/script-opts/file-browser/filter.conf
opt.read_options(o, "file-browser/filter")

local parser = {
    priority = 10,
    version = "1.3.0"
}

local paths = {}
for str in fb.iterate_opt(o.paths) do
    paths[str] = true
end

local function filter(path)
    return paths[path]
end

function parser:can_parse()
    return true
end

function parser:parse(directory)
    local list, opts = self:defer(directory)
    if not list then return list, opts end

    directory = opts.directory or directory

    for i=#list, 1, -1 do
        if filter( fb.get_full_path(list[i], directory) ) then
            table.remove(list, i)
        end
   end

    return list, opts
end

return parser

If you want to make it more user friendly then you'll have to do so yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
use-addons request should be completed with an addon
Projects
None yet
Development

No branches or pull requests

2 participants