feat(nvim): add Tmp user command

This commit is contained in:
Price Hiller 2024-03-10 21:09:06 -05:00
parent b4609ba7bd
commit 1a1324761a
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -102,7 +102,22 @@ M.setup = function()
vim.bo.readonly = false
end, {
nargs = "*",
desc = "Sudo Write"
desc = "Sudo Write",
})
vim.api.nvim_create_user_command("Tmp", function(opts)
local fname = vim.trim(opts.args)
local tmp_dir = vim.fn.fnamemodify(vim.fn.tempname(), ":p:h")
vim.cmd.cd(tmp_dir)
if fname ~= "" then
vim.cmd.edit({ args = { fname }, bang = true })
vim.cmd.write({ bang = true })
else
vim.cmd.edit({ args = { tmp_dir } })
end
end, {
nargs = "*",
desc = "Create tempfile and cd to its directory",
})
end