diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2023-07-14 17:19:44 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2023-07-14 17:19:44 -0500 |
commit | 0890ced31258325c922f0f67a24ee8dc5a8ba673 (patch) | |
tree | ba47a31cd57aeb9f6b25d1b6cbc9a675275c454c | |
parent | d8cdb2f82ea6d6a87d8e15e0dcbbf6abfb4045ab (diff) |
fix(nvim): filetype when using `sudoedit`/`sudo -e`
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/filetype.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/filetype.lua b/nvim/.config/nvim/lua/tobyvin/filetype.lua index 6e52fdd..e98f5b8 100644 --- a/nvim/.config/nvim/lua/tobyvin/filetype.lua +++ b/nvim/.config/nvim/lua/tobyvin/filetype.lua @@ -9,5 +9,20 @@ vim.filetype.add({ }, pattern = { [".*%.conf"] = { "confini", { priority = -math.huge } }, + ["/var/tmp/.*"] = function(_, bufnr, _) + local pid = vim.fn.getpid() + local cl = vim.fn.readfile(("/proc/%s/comm"):format(pid)) + + while #cl >= 1 and cl[1] == "nvim" do + pid = vim.fn.split(vim.fn.readfile(("/proc/%s/stat"):format(pid))[1])[4] + cl = vim.fn.split(vim.fn.readfile(("/proc/%s/cmdline"):format(pid))[1], "\n") + + if #cl >= 1 and cl[1] == "sudoedit" or (#cl >= 2 and cl[1] == "sudo" and cl[2] == "-e") then + return vim.filetype.match({ buf = bufnr, filename = cl[#cl] }) + end + end + + return vim.filetype.match({ buf = bufnr }) + end, }, }) |