From dee4b834c5295fd88b220d8146309a1f38cbc56d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 23 Jan 2022 15:48:04 +0100 Subject: Add unmount command --- lua/rclone.lua | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'lua/rclone.lua') 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, } --- -- cgit v1.2.3