diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-06 15:29:58 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-06 15:29:58 +0200 |
commit | ad05cb18f03f3a97a918e090c38ba760147a0bb6 (patch) | |
tree | 233097b3ccbf1a4fef18a291d0d8fda3fba34c03 /config/essentials/nvim/lua/user/live-server.lua | |
parent | 1a7e35285abb5db60d2e1544ce0100e82c5d3490 (diff) | |
parent | 511b6c1bc9acd9e6029d08a6c448f6e0037755fb (diff) |
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'config/essentials/nvim/lua/user/live-server.lua')
-rw-r--r-- | config/essentials/nvim/lua/user/live-server.lua | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/config/essentials/nvim/lua/user/live-server.lua b/config/essentials/nvim/lua/user/live-server.lua deleted file mode 100644 index 197809d..0000000 --- a/config/essentials/nvim/lua/user/live-server.lua +++ /dev/null @@ -1,60 +0,0 @@ -local M = {} --- keep track of jobs -local live_servers = {} - -function M.start_live_server() - if vim.fn.executable('lsof') == 0 then - print("Error: 'lsof' command not found") - elseif vim.fn.executable('live-server') == 0 then - print("Error: 'live-server' command not found") - return - end - - -- Search for available port and use it - local port = 5500 - local running = true - while running do - local output = vim.fn.systemlist('lsof -i :' .. port) - if #output == 0 then - running = false - else - port = port + 1 - end - end - - local command = "live-server --no-browser --port=" .. port .. " \"" .. vim.fn.expand("%:p:h") .. "\"" - -- run - local job_id = vim.fn.jobstart(command, { - on_exit = function(_, _, _) end - }) - -- save - live_servers[port] = job_id - - print("Started live-server on :" .. port .. ".") -end - -function M.stop_live_servers() - for port, job_id in pairs(live_servers) do - local output = vim.fn.systemlist('lsof -i :' .. port) - if #output > 0 then - vim.fn.jobstop(job_id) - print("Killed live-server on :" .. port .. ".") - end - live_servers[port] = nil - end -end - -vim.api.nvim_create_user_command("LiveServer", function(opts) - local opt = string.format(opts.args) - if #opts.args == 0 then - M.start_live_server() - elseif opt == "start" then - M.start_live_server() - elseif opt == "stop" then - M.stop_live_servers() - else - print("Invalid argument. Usage: LiveServer [start|stop]") - end -end, { nargs = '*' }) - -return M |