Skip to content

Commit

Permalink
winroot: upload addon (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
CogentRedTester committed Oct 10, 2022
1 parent 92d1652 commit 4a9fe29
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Implements support for ftp file servers. Requires `curl` in the system path.
**home-label**
Replaces the user's home directory in the directory header with `~/`.

**win-root**
Automatically populates the root with windows drives.

**url-decode**
Decodes URL directories to make them more readable. Does not decode the names of items in the list.

Expand Down
63 changes: 63 additions & 0 deletions addons/winroot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--[[
Automatically populates the root with windows drives on startup.
Ctrl+r will add new drives mounted since startup.
Drives will only be added if they are not already present in the root.
Available at: https://github.com/CogentRedTester/mpv-file-browser/tree/master/addons
]]

local mp = require 'mp'
local msg = require 'mp.msg'
local fb = require 'file-browser'

-- returns a list of windows drives
local function get_drives()
local result = mp.command_native({
name = 'subprocess',
playback_only = false,
capture_stdout = true,
args = {'wmic', 'logicaldisk', 'get', 'caption'}
})
if result.status ~= 0 then return msg.error('could not read windows root') end

local root = {}
for drive in result.stdout:gmatch("%a:") do
table.insert(root, drive..'/')
end
return root
end

-- returns true if the given drive is in the given root list
local function in_root(drive, root)
for _, item in ipairs(root) do
if item.name == drive then return true end
end
return false
end

-- adds windows drives to the root if they are not already present
local function import_drives()
local drives = get_drives()
local root = fb.get_root()

for _, drive in ipairs(drives) do
if not in_root(drive, root) then
fb.insert_root_item({ name = drive })
end
end
end

local keybind = {
key = 'Ctrl+r',
name = 'import_root_drives',
command = import_drives,
parser = 'root',
passthrough = true
}

return {
version = '1.3.0',
setup = import_drives,
keybinds = { keybind }
}

0 comments on commit 4a9fe29

Please sign in to comment.