From ae6bb93ba269e923592d2a6675962543ca744974 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 6 Feb 2022 12:36:31 +0100 Subject: Add option to download directories --- lua/rclone.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lua/rclone.lua') diff --git a/lua/rclone.lua b/lua/rclone.lua index 51346e7..0f94916 100644 --- a/lua/rclone.lua +++ b/lua/rclone.lua @@ -342,9 +342,23 @@ local function downloadFile(options) local local_path = prepare_cmd_local_path(config) - -- build relative path to file for local and remote + -- build path to file for local and remote local Path = require('plenary.path') - local local_file_path = Path:new(vim.fn.expand('%')):absolute() + local local_file_path = '' + + if options['directory'] then + local_file_path = Path:new(vim.fn.expand(options['directory'])) + + if local_file_path:exists() ~= true then + print('Directory "' .. local_file_path:absolute() .. '" to download to missing') + return + end + + local_file_path = local_file_path:absolute() + else + local_file_path = Path:new(vim.fn.expand('%')):absolute() + end + local local_path_pattern = vim.pesc(local_path) if local_file_path:find(local_path_pattern) == nil then @@ -355,6 +369,10 @@ local function downloadFile(options) 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 + if options['directory'] then + local_file_path_relative_parent = local_file_path_relative + end + local cmd = 'rclone copy ' .. build_cmd_remote_path(config, remote) .. local_file_path_relative .. ' ' .. -- cgit v1.2.3