From f082f8ce234a69a419ec256259dc3ded6abecd71 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 13 Dec 2021 14:40:05 +0100 Subject: Add copyFile command --- lua/rclone.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lua') diff --git a/lua/rclone.lua b/lua/rclone.lua index 693d8ef..54ae939 100644 --- a/lua/rclone.lua +++ b/lua/rclone.lua @@ -228,6 +228,40 @@ local function copy(remote_section) return config end +--- +-- Call the 'rclone copy' command with config values for the current file +-- 'rclone copy ' +-- +-- @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 ' @@ -258,6 +292,7 @@ end return { copy = copy, + copyFile = copyFile, sync = sync, } -- cgit v1.2.3