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 +++++++++++++++++++++++++++++++++++ plugin/rclone.vim | 2 ++ 2 files changed, 37 insertions(+) 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, } diff --git a/plugin/rclone.vim b/plugin/rclone.vim index 3173b6a..31c3f1b 100644 --- a/plugin/rclone.vim +++ b/plugin/rclone.vim @@ -6,8 +6,10 @@ let s:old_cpo = &cpo set cpo&vim command! -nargs=? RcloneCopy lua require('rclone').copy() +command! -nargs=? RcloneCopyFile lua require('rclone').copyFile() command! -nargs=? RcloneSync lua require('rclone').sync() + let &cpo = s:old_cpo unlet s:old_cpo -- cgit v1.2.3