summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/rclone.lua45
1 files changed, 38 insertions, 7 deletions
diff --git a/lua/rclone.lua b/lua/rclone.lua
index 924b7d8..6df5efb 100644
--- a/lua/rclone.lua
+++ b/lua/rclone.lua
@@ -60,12 +60,12 @@ local function get_remote_config(remote)
local target_config = nil
if remote then
- for remote_name, remote_config in pairs(config) do
- if remote_name == remote then
- target_remote = remote_name
- target_config = remote_config
- end
- end
+ if config[remote] then
+ target_remote = remote
+ target_config = config[remote]
+ else
+ print("Couldn't find remote: " .. remote)
+ end
else
local config_length = 0
for _, _ in pairs(config) do
@@ -89,6 +89,7 @@ local function get_remote_config(remote)
if target_remote == nil then
print("Couldn't find suitable remote")
+ -- TODO: check how to do error handling in lua/vim plugins
end
return target_remote, target_config
@@ -105,8 +106,38 @@ local function copy()
local local_path = Path:new(config.vim_rclone_local_path)
local_path._cwd = config_dir -- set cwd to config dir to resolve path correctly
+ local_path = local_path:absolute()
+ local_path = local_path:gsub('%./', '') -- remove wrongly kept ./ for relative paths
+
+ local cmd =
+ 'rclone copy ' ..
+ local_path .. ' ' ..
+ remote .. ':' .. config.vim_rclone_remote_path ..
+ ' --config=' .. find_config_file()
+
+ -- TODO: add configurable default exclude patterns
+ local configurable_default_exclude_patterns = {'.git/'}
+ for _, pattern in pairs(configurable_default_exclude_patterns) do
+ cmd = cmd .. ' --exclude=' .. pattern
+ end
+
+ -- add .gitignore patterns
+ local gitignore = Path:new(local_path .. '/.gitignore')
+ if gitignore:exists() then
+ cmd = cmd .. ' --exclude-from=' .. gitignore.filename
+ end
+
+ -- add .rcloneignore patterns
+ local rcloneignore = Path:new(local_path .. '/.rcloneignore')
+ if rcloneignore:exists() then
+ cmd = cmd .. ' --exclude-from=' .. rcloneignore.filename
+ end
+
+ -- TODO: add --log-level=INFO --log-file=.local/share/nvim/rclone_nvim/rclone.log
- print('rclone copy ' .. local_path:absolute() .. ' ' .. remote .. ':' .. config.vim_rclone_remote_path .. ' --config=' .. find_config_file())
+ os.execute(cmd)
+ print(cmd)
+ print("Copied!")
return config
end