summaryrefslogtreecommitdiff
path: root/lua/rclone.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/rclone.lua')
-rw-r--r--lua/rclone.lua39
1 files changed, 38 insertions, 1 deletions
diff --git a/lua/rclone.lua b/lua/rclone.lua
index d7e14c7..2749953 100644
--- a/lua/rclone.lua
+++ b/lua/rclone.lua
@@ -439,13 +439,49 @@ local function mount(options)
'--daemon'
if options['--dry-run'] then
+ if options['--return'] then
+ return cmd
+ end
+
print(cmd)
else
- os.execute('mkdir ' .. local_mount_path)
+ os.execute('mkdir -p ' .. local_mount_path)
os.execute(cmd)
end
end
+---
+-- Unmount mount mounted with 'rclone mount'
+--
+-- @return any
+local function unmount(options)
+ local mount_options = vim.deepcopy(options)
+ mount_options['--dry-run'] = true
+ mount_options['--return'] = true
+ local mount_cmd = mount(mount_options)
+
+ local pid_cmd = "ps aux | grep -i '" .. mount_cmd .. "' | grep -v grep | awk '{print $2}'"
+ local cmd = function (pid)
+ return 'kill ' .. pid
+ end
+
+ if options['--dry-run'] then
+ print(pid_cmd)
+ print(cmd('$PID_RETURNED_FROM_CMD_ABOVE'))
+ else
+ local pid_handle = io.popen(pid_cmd)
+ local pid = pid_handle:read()
+ pid_handle:close()
+
+ if pid == nil then
+ print('No pid found for mount process')
+ return
+ end
+
+ os.execute(cmd(pid))
+ end
+end
+
-- Table for dynamic command access
local commands = {
copy = copy,
@@ -454,6 +490,7 @@ local commands = {
downloadFile = downloadFile,
sync = sync,
mount = mount,
+ unmount = unmount,
}
---