summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/rclone.lua91
1 files changed, 91 insertions, 0 deletions
diff --git a/lua/rclone.lua b/lua/rclone.lua
index c4eb680..fe0b85a 100644
--- a/lua/rclone.lua
+++ b/lua/rclone.lua
@@ -282,6 +282,95 @@ local function copyFile(options)
end
---
+-- Call the 'rclone copy' command with config values
+-- 'rclone copy <args>'
+--
+-- @return any
+local function download(options)
+ local remote, config = get_remote_config(options.remote)
+ if remote == nil then
+ return
+ end
+
+ local local_path = prepare_cmd_local_path(config)
+
+ local cmd =
+ 'rclone copy ' ..
+ build_cmd_remote_path(config, remote) .. ' ' ..
+ local_path .. ' ' ..
+ build_cmd_config() .. ' ' ..
+ build_cmd_exclude(local_path) .. ' ' ..
+ build_cmd_logging()
+
+ if options['--dry-run'] then
+ print(cmd)
+ else
+ if vim.fn.confirm('Download?', '&Yes\n&No') == 1 then
+ os.execute(cmd)
+ vim.cmd([[
+ let curBuf=bufnr('%')
+ execute 'bufdo execute "confirm e" | update'
+ execute 'buffer ' . curBuf
+ ]])
+ else
+ print('Download canceled!')
+ return
+ end
+ end
+
+ print('Downloaded!')
+end
+
+---
+-- Call the 'rclone copy' command with config values for the current file
+-- 'rclone copy <args>'
+--
+-- @return any
+local function downloadFile(options)
+ local remote, config = get_remote_config(options.remote)
+ if remote == nil then
+ return
+ end
+
+ local local_path = prepare_cmd_local_path(config)
+
+ -- build relative path to file for local and remote
+ local Path = require('plenary.path')
+ local local_file_path = Path:new(vim.fn.expand('%')):absolute()
+ local local_path_pattern = vim.pesc(local_path)
+
+ if local_file_path:find(local_path_pattern) == nil then
+ print('File path not in local path')
+ return
+ end
+
+ local local_file_path_relative = local_file_path:gsub(local_path_pattern, '')
+ local local_file_path_relative_parent = Path:new(local_file_path_relative):parent().filename
+
+ local cmd =
+ 'rclone copy ' ..
+ build_cmd_remote_path(config, remote) .. local_file_path_relative .. ' ' ..
+ local_path .. local_file_path_relative_parent .. ' ' ..
+ build_cmd_config() .. ' ' ..
+ build_cmd_exclude(local_path) .. ' ' ..
+ build_cmd_logging()
+
+ if options['--dry-run'] then
+ print(cmd)
+ else
+ if vim.fn.confirm('Download file?', '&Yes\n&No') == 1 then
+ os.execute(cmd)
+ vim.api.nvim_command('confirm e')
+ else
+ print('Download file canceled!')
+ return
+ end
+ end
+
+ print('Downloaded file!')
+end
+
+---
-- Call the 'rclone sync' command with config values
-- 'rclone sync <args>'
--
@@ -317,6 +406,8 @@ end
local commands = {
copy = copy,
copyFile = copyFile,
+ download = download,
+ downloadFile = downloadFile,
sync = sync,
}