From 1a1324761aab1e00a66920aedbc40bdd981c3d06 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 10 Mar 2024 21:09:06 -0500 Subject: [PATCH] feat(nvim): add `Tmp` user command --- dots/.config/nvim/lua/core/cmds.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dots/.config/nvim/lua/core/cmds.lua b/dots/.config/nvim/lua/core/cmds.lua index 75773642..ce1866b8 100644 --- a/dots/.config/nvim/lua/core/cmds.lua +++ b/dots/.config/nvim/lua/core/cmds.lua @@ -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