irongit

Configure synchronization of files and directories through a plugin.

added user commands

huncholanehuncholaneauthored
parent fb609cccommit cd5b1f7df24704c084600795ebf49850b7cd8626Browse files

3 files changed, +31 -5

+11-0lua/syncmap/commands.lua
@@ -0,0 +1,11 @@
1+local M = {
2+ opts = require("syncmap.default"),
3+}
4+local state = require("syncmap.state")
5+
6+function M.setup()
7+ vim.api.nvim_create_user_command("SyncmapRestart", state.restart, {})
8+ vim.api.nvim_create_user_command("SyncmapStop", state.clear, {})
9+end
10+
11+return M
+4-1lua/syncmap/init.lua
@@ -4,6 +4,7 @@ M.rsync = require("syncmap.rsync")
44 M.utils = require("syncmap.utils")
55 M.default = require("syncmap.default")
66 M.log = require("syncmap.log")
7+M.commands = require("syncmap.commands")
78
89 M.opts = M.default
910
@@ -15,7 +16,9 @@ function M.setup(opts)
1516 M.state.opts = M.opts
1617 M.rsync.opts = M.opts
1718 M.log.opts = M.opts
18- M.state.sync(M.opts)
19+ M.commands.opts = M.opts
20+ M.state.sync()
21+ M.commands.setup()
1922 end
2023
2124 ---Shows the current state of Syncmap
+16-4lua/syncmap/state.lua
@@ -48,8 +48,8 @@ end
4848 load_state()
4949
5050 ---Removes stale states, calls reverse_rsync on new folders, and starts watch on dead pids
51----@param opts FinalSyncmapOpts
52-function M.sync(opts)
51+function M.sync()
52+ local opts = M.opts
5353 ---@type table<RsyncPath, SyncmapConfigMatch>
5454 local lookup = {}
5555 for _, m in ipairs(opts.map) do
@@ -96,10 +96,16 @@ function M.save()
9696 fd:close()
9797 end
9898
99+---Kills all the active inotifywatch servers
100+function M.killall()
101+ for src in M.active do
102+ utils.kill(src)
103+ end
104+end
105+
99106 ---Clears the saved information by deleting the state file
100107 function M.clear()
101- for _, a in ipairs(M.active) do
102- end
108+ M.killall()
103109 local ok, err = os.remove(M.state_file)
104110 if not ok then
105111 log.error("Failed to delete state file: " .. err)
@@ -108,4 +114,10 @@ function M.clear()
108114 end
109115 end
110116
117+---Restarts Syncmap
118+function M.restart()
119+ M.killall()
120+ M.sync()
121+end
122+
111123 return M