summaryrefslogtreecommitdiff
path: root/lua/config/sudo.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config/sudo.lua')
-rw-r--r--lua/config/sudo.lua45
1 files changed, 0 insertions, 45 deletions
diff --git a/lua/config/sudo.lua b/lua/config/sudo.lua
deleted file mode 100644
index b9c9299..0000000
--- a/lua/config/sudo.lua
+++ /dev/null
@@ -1,45 +0,0 @@
--- ~/.config/nvim/lua/config/sudo.lua
--- :Sudow - Write the current buffer with sudo privileges
-
-vim.api.nvim_create_user_command("Sudow", function()
- local filepath = vim.fn.expand("%:p")
- if filepath == "" then
- vim.notify("No file to write", vim.log.levels.ERROR)
- return
- end
-
- -- Prompt for password
- local password = vim.fn.inputsecret("Mot de passe: ")
- if password == "" then
- vim.notify("Cancelled", vim.log.levels.WARN)
- return
- end
-
- -- Write buffer contents to a temp file
- local tmpfile = vim.fn.tempname()
- vim.cmd("silent write! " .. vim.fn.fnameescape(tmpfile))
-
- -- Use sudo to copy temp file to target
- local cmd = string.format(
- "echo %s | sudo -S cp %s %s 2>&1",
- vim.fn.shellescape(password),
- vim.fn.shellescape(tmpfile),
- vim.fn.shellescape(filepath)
- )
- local output = vim.fn.system(cmd)
- local success = vim.v.shell_error == 0
-
- -- Clean up temp file
- os.remove(tmpfile)
-
- if success then
- -- Reload buffer to clear modified flag
- vim.cmd("edit!")
- vim.notify("Written with sudo: " .. filepath, vim.log.levels.INFO)
- else
- vim.notify("sudo write failed: " .. output, vim.log.levels.ERROR)
- end
-end, { desc = "Write current buffer with sudo" })
-
--- Allow lowercase :sudow to expand to :Sudow
-vim.cmd("cnoreabbrev sudow Sudow")