feat: take in optional dir arg
This commit is contained in:
parent
f34ae262bf
commit
da3496d878
1 changed files with 17 additions and 11 deletions
|
|
@ -33,14 +33,13 @@ M.config = {
|
||||||
args = { '--port=5555' },
|
args = { '--port=5555' },
|
||||||
}
|
}
|
||||||
|
|
||||||
M.toggle = function()
|
M.toggle = function(dir)
|
||||||
local dir = vim.fn.expand '%:p:h'
|
|
||||||
local running = is_running(dir)
|
local running = is_running(dir)
|
||||||
if not running then
|
if not running then
|
||||||
M.start()
|
M.start(dir)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
M.stop()
|
M.stop(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setup = function(user_config)
|
M.setup = function(user_config)
|
||||||
|
|
@ -54,13 +53,21 @@ M.setup = function(user_config)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('LiveServerStart', M.start, {})
|
vim.api.nvim_create_user_command('LiveServerStart', function(opts)
|
||||||
vim.api.nvim_create_user_command('LiveServerStop', M.stop, {})
|
local dir = opts.args ~= '' and opts.args or '%:p:h'
|
||||||
vim.api.nvim_create_user_command('LiveServerToggle', M.toggle, {})
|
M.start(vim.fn.expand(dir))
|
||||||
|
end, { nargs = '?' })
|
||||||
|
vim.api.nvim_create_user_command('LiveServerStop', function(opts)
|
||||||
|
local dir = opts.args ~= '' and opts.args or '%:p:h'
|
||||||
|
M.stop(vim.fn.expand(dir))
|
||||||
|
end, { nargs = '?' })
|
||||||
|
vim.api.nvim_create_user_command('LiveServerToggle', function(opts)
|
||||||
|
local dir = opts.args ~= '' and opts.args or '%:p:h'
|
||||||
|
M.toggle(vim.fn.expand(dir))
|
||||||
|
end, { nargs = '?' })
|
||||||
end
|
end
|
||||||
|
|
||||||
M.start = function()
|
M.start = function(dir)
|
||||||
local dir = vim.fn.expand '%:p:h'
|
|
||||||
local running = is_running(dir)
|
local running = is_running(dir)
|
||||||
|
|
||||||
if running then
|
if running then
|
||||||
|
|
@ -96,8 +103,7 @@ M.start = function()
|
||||||
job_cache[dir] = job_id
|
job_cache[dir] = job_id
|
||||||
end
|
end
|
||||||
|
|
||||||
M.stop = function()
|
M.stop = function(dir)
|
||||||
local dir = vim.fn.expand '%:p:h'
|
|
||||||
local running = is_running(dir)
|
local running = is_running(dir)
|
||||||
|
|
||||||
if running then
|
if running then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue