summaryrefslogtreecommitdiff
path: root/mpv/scripts/file-browser/modules/addons/home-label.lua
blob: 5e6cf8e135a950e08f9f868f5c827adda475e441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--[[
    An addon for mpv-file-browser which displays ~/ for the home directory instead of the full path
]]--

local mp = require "mp"
local fb = require "file-browser"

local home = fb.fix_path(mp.command_native({"expand-path", "~/"}) --[[@as string]], true)

---@type ParserConfig
local home_label = {
    priority = 100,
    api_version = "1.0.0"
}

function home_label:can_parse(directory)
    if not fb.get_opt('home_label') then return false end
    return directory:sub(1, home:len()) == home
end

---@async
function home_label:parse(directory)
    local list, opts = self:defer(directory)
    if not opts then opts = {} end
    if (not opts.directory or opts.directory == directory) and not opts.directory_label then
        opts.directory_label = "~/"..(directory:sub(home:len()+1) or "")
    end
    return list, opts
end

return home_label