zed icon indicating copy to clipboard operation
zed copied to clipboard

Ask for sudo/admin on files saving if required

Open itsbalamurali opened this issue 1 year ago • 3 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Screenshot of VS Code image

try editing /etc/hosts file in zed.

Environment

MacOS

If applicable, add mockups / screenshots to help explain present your vision of the feature

image

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log

itsbalamurali avatar Jun 19 '24 11:06 itsbalamurali

@itsbalamurali i think the best way to do it is to save a temporary copy of the modified file in a $USER repo like .cache or /tmp folder and then move it to the original file location while using pkexec . i am working on a script for this method . any help is appreciated ! this was my simple implementation in neovim (it is simple and usually barely make problems )

meduk0 avatar Feb 28 '25 06:02 meduk0

Heya Zed team!

Don't intent to add noise to the convo, rather just comment out this is still a pretty needed thing and I'll argue this is a bit priority, for additional context SublimeText does this as well:

Image

btw, thanks to the ZED team, the editor is getting better and better, much appreciated.

Esteban-Rocha avatar May 06 '25 00:05 Esteban-Rocha

@itsbalamurali i think the best way to do it is to save a temporary copy of the modified file in a $USER repo like .cache or /tmp folder and then move it to the original file location while using pkexec . i am working on a script for this method . any help is appreciated ! this was my simple implementation in neovim (it is simple and usually barely make problems )

This is essentially re-implementing sudoedit / sudo -e behavior

Malix-Labs avatar Jun 02 '25 22:06 Malix-Labs

@itsbalamurali i think the best way to do it is to save a temporary copy of the modified file in a $USER repo like .cache or /tmp folder and then move it to the original file location while using pkexec . i am working on a script for this method . any help is appreciated ! this was my simple implementation in neovim (it is simple and usually barely make problems )

a way that avoids creating temporary file is piping into pkexec tee <outfile>

ambyjkl avatar Jul 12 '25 12:07 ambyjkl

This is becoming my highest pain point with Zed, as I sometimes need to edit root config files and Zed seems to also be incapable of being used for sudoedit, so I have to revert back to using Vscode for such uses

edit: forget about it, sudoedit works now, hiding myself as resolved

Malix-Labs avatar Aug 11 '25 13:08 Malix-Labs

This is becoming my highest pain point with Zed, as I sometimes need to edit root config files and Zed seems to also be incapable of being used for sudoedit, so I have to revert back to using Vscode for such uses

edit: forget about it, sudoedit works now, hiding myself as resolved

You should try the Micro editor, it can run in the zed terminal and has sudo support, and similar keybinds to vscode, so don't need to open vscode

ambyjkl avatar Aug 11 '25 19:08 ambyjkl

I'd love to get this too. I want to use zed everywhere and I've tried setting

 EDITOR = "zed --wait";

to use for commands like vifs, but:

❯ vifs
vifs: need to run as root

~
❯ sudo vifs
Password:
Error: Running Zed as root or via sudo is unsupported.
       Doing so (even once) may subtly break things for all subsequent non-root usage of Zed.
       It is untested and not recommended, don't complain when things break.
       If you wish to proceed anyways, set `ZED_ALLOW_ROOT=true` in your environment.
vifs: editing error

❯ echo $ZED_ALLOW_ROOT
true

hedefalk avatar Aug 25 '25 12:08 hedefalk

Is it even possible to edit a file that requires sudo permission? I cannot even run zed with sudo (saying it is untested and not recommended).

Jason5Lee avatar Oct 24 '25 09:10 Jason5Lee

@Jason5Lee use sudoedit (or any tool that achieves a similar job)

Malix-Labs avatar Oct 24 '25 18:10 Malix-Labs

Is it even possible to edit a file that requires sudo permission? I cannot even run zed with sudo (saying it is untested and not recommended).

Exact : I have done a symlink : sudo ln -s ~/.local/bin/zed /usr/local/bin/zed

And now when editing a file with sudo zed myFile I have this warning :

Error: Running Zed as root or via sudo is unsupported.
       Doing so (even once) may subtly break things for all subsequent non-root usage of Zed.
       It is untested and not recommended, don't complain when things break.
       If you wish to proceed anyways, set `ZED_ALLOW_ROOT=true` in your environment.

Not sure what can break

rattlesnake2028 avatar Nov 01 '25 10:11 rattlesnake2028