Skip to content

Instantly share code, notes, and snippets.

@alexandr-san4ez
Last active March 27, 2017 19:47
Show Gist options
  • Save alexandr-san4ez/6fa43e7bbf846bf89f011e65085f5bd6 to your computer and use it in GitHub Desktop.
Save alexandr-san4ez/6fa43e7bbf846bf89f011e65085f5bd6 to your computer and use it in GitHub Desktop.
Clink-completions for megatools and cmd file for use megatools (https://github.com/megous/megatools)
@echo off
set MEGAPATH=C:\path\Megatools
IF "%1"=="-h" (
echo All commands:
echo reg - Register and verify a new mega account.
echo df - Show your cloud storage space usage/quota.
echo ls - List all remote files.
echo mkdir - Create remote directory.
echo rm - Remove remote file or directory.
echo put - Upload individual files.
echo get - Download individual files.
echo dl - Download file from a 'public' Mega link ^(doesn't require login^).
echo copy - Upload or download a directory tree.
GOTO:EOF
)
IF "%1"=="" (
echo Enter: "mega <command> [params]"
echo Help: "mega -h"
) ELSE (
IF "%1"=="dl" (
call "%MEGAPATH%"\mega%*
) ELSE (
call "%MEGAPATH%"\mega%* --config "%MEGAPATH%\mega.ini"
)
)
local w = require('tables').wrap
local function get_remote_paths ()
local result = w()
local proc = io.popen("mega ls -l 2>nul")
if not proc then return result end
for line in proc:lines() do
local tp = line:sub(25, 25) -- type
local name = line:sub(61, #line)
if not (tp == '0') then table.insert(result, name) end
end
proc:close()
return result
end
local parser = clink.arg.new_parser
local remote_path_parser = parser({get_remote_paths})
local mega_parser = parser({
"reg",
"df",
"rm",
"dl",
"ls" .. remote_path_parser,
"mkdir" .. remote_path_parser,
"get" .. remote_path_parser,
"put" .. parser(
"--path" .. remote_path_parser
),
"copy" .. parser(
"-r" .. remote_path_parser,
"--remote" .. remote_path_parser
)
})
clink.arg.register_parser("mega", mega_parser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment