summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-02-06 12:36:31 +0100
committerDaniel Weipert <code@drogueronin.de>2022-02-06 12:36:31 +0100
commitae6bb93ba269e923592d2a6675962543ca744974 (patch)
treeabf666f679bcc42f4b5b541905a29d3eb92fcb43
parent8c129f92b86e1686bc0cd59bd141bb2c4d0bf466 (diff)
Add option to download directories
-rw-r--r--lua/rclone.lua22
1 files changed, 20 insertions, 2 deletions
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 .. ' ' ..