summaryrefslogtreecommitdiff
path: root/lua/rclone.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/rclone.lua')
-rw-r--r--lua/rclone.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/rclone.lua b/lua/rclone.lua
index 693d8ef..54ae939 100644
--- a/lua/rclone.lua
+++ b/lua/rclone.lua
@@ -229,6 +229,40 @@ local function copy(remote_section)
end
---
+-- Call the 'rclone copy' command with config values for the current file
+-- 'rclone copy <args>'
+--
+-- @return any
+local function copyFile(remote_section)
+ local remote, config = get_remote_config(remote_section)
+ 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_file_path_relative = local_file_path:gsub(local_path:gsub('([^%w])', '%%%1'), '')
+ local local_file_path_relative_parent = Path:new(local_file_path_relative):parent().filename
+
+ local cmd =
+ 'rclone copy ' ..
+ local_path .. local_file_path_relative .. ' ' ..
+ build_cmd_remote_path(config, remote) .. local_file_path_relative_parent .. ' ' ..
+ build_cmd_config() .. ' ' ..
+ build_cmd_exclude(local_path) .. ' ' ..
+ build_cmd_logging()
+
+ os.execute(cmd)
+ print(cmd)
+ print("Copied file!")
+
+ return config
+end
+
+---
-- Call the 'rclone sync' command with config values
-- 'rclone sync <args>'
--
@@ -258,6 +292,7 @@ end
return {
copy = copy,
+ copyFile = copyFile,
sync = sync,
}