home-label.lua (850B)
1 --[[ 2 An addon for mpv-file-browser which displays ~/ for the home directory instead of the full path 3 ]]-- 4 5 local mp = require "mp" 6 local fb = require "file-browser" 7 8 local home = fb.fix_path(mp.command_native({"expand-path", "~/"}) --[[@as string]], true) 9 10 ---@type ParserConfig 11 local home_label = { 12 priority = 100, 13 api_version = "1.0.0" 14 } 15 16 function home_label:can_parse(directory) 17 if not fb.get_opt('home_label') then return false end 18 return directory:sub(1, home:len()) == home 19 end 20 21 ---@async 22 function home_label:parse(directory) 23 local list, opts = self:defer(directory) 24 if not opts then opts = {} end 25 if (not opts.directory or opts.directory == directory) and not opts.directory_label then 26 opts.directory_label = "~/"..(directory:sub(home:len()+1) or "") 27 end 28 return list, opts 29 end 30 31 return home_label