summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2021-12-13 14:40:05 +0100
committerDaniel Weipert <code@drogueronin.de>2022-01-10 13:28:28 +0100
commitf082f8ce234a69a419ec256259dc3ded6abecd71 (patch)
tree9cd1da6b662c883283d4b9700e3b202d06ed311d
parentca44f39a27073c708857d15d363fe880165028e8 (diff)
Add copyFile command
-rw-r--r--lua/rclone.lua35
-rw-r--r--plugin/rclone.vim2
2 files changed, 37 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,
}
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(<f-args>)
+command! -nargs=? RcloneCopyFile lua require('rclone').copyFile(<f-args>)
command! -nargs=? RcloneSync lua require('rclone').sync(<f-args>)
+
let &cpo = s:old_cpo
unlet s:old_cpo