Repository navigation
Keep the sudo editor on one that blocks - #9503
d-zalewski wants to merge 2 commits into
Conversation
sudo hands the editor a temporary copy and keeps whatever is on disk once the editor exits. SUDO_EDITOR was "$EDITOR", which is omarchy-launch-editor --inline, and that detaches every graphical editor with setsid uwsm-app. The launcher returns immediately, so visudo and sudoedit see a file that closed without changing and discard the edit -- no error, and the editor window opens on a file that is already gone. That is five of the eight editors omarchy-default-editor offers: code, cursor, zed, sublime_text, and emacs. Only nvim, vim, and helix block today, which is why the default hides it. Add a --sudo mode that runs a terminal editor in place and falls back to nvim rather than detach, and point SUDO_EDITOR at it. An EDITOR the user set themselves is left alone, and an explicit SUDO_EDITOR still wins over both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
quattro now passes `--` before the path on every editor launch (omacom#11495), so the --sudo fallback does the same and the tests expect it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed and verified on a disposable Omarchy worker, and I pushed one commit: a merge of Reproduction. On the worker, with zed installed and set as the default editor,
Two claims in the description and comments do not hold:
Competing fixes. #13044 and #13094 (for #13037) fix the same root cause from the other side: they make No second opinion. The configured reviewer (Codex Medium) answers its health check, but today's review budget was spent, so nothing reviewed this beyond my own review (Claude Opus 5.5). Without that review this cannot be marked ready. Waiting on the maintainer: to choose between this approach and #13044 / #13094, and for a second-opinion review on a later run. |
|
| # terminal editor. An EDITOR the user set themselves is left to them, and an | ||
| # explicit SUDO_EDITOR still wins over both. | ||
| if [[ $EDITOR == "omarchy-launch-editor --inline" ]]; then | ||
| export SUDO_EDITOR="${SUDO_EDITOR:-omarchy-launch-editor --sudo}" |
There was a problem hiding this comment.
Inherited editor still detaches
If a new shell inherits the old Omarchy value SUDO_EDITOR=omarchy-launch-editor --inline, this assignment preserves it instead of selecting --sudo. With a graphical default editor, sudoedit or visudo still launches the editor detached and discards the edit, so the bug this PR intends to fix remains reachable after an upgrade.
| *) | ||
| exec setsid uwsm-app -- "$editor" -- "$@" | ||
| if [[ $mode == "sudo" ]]; then | ||
| exec nvim -- "$@" |
There was a problem hiding this comment.
| fail "--sudo does not hand $editor to a separate terminal" "got: $launched" | ||
| done | ||
|
|
||
| pass "--sudo blocks for every editor the chooser offers" |
There was a problem hiding this comment.
Blocking behavior remains untested
The test reports that --sudo blocks, but its editor stubs exit immediately and the assertions check only logged arguments. A path that launches a different non-blocking editor could still pass, leaving the behavior this test is meant to protect unverified. A process-liveness check would cover that gap.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Greptile's three findings on 7bd2e67, checked against the source by me (Claude Opus 5.5) alone. The configured second opinion (Codex Medium) answers its health check but the day's review budget is spent again, so nothing else has checked this.
Nothing else has changed: this is still waiting on the maintainer to choose between this approach and #13044 / #13094, and on a second-opinion review. |
|
I looked at this again because it stopped merging cleanly. The head is still 7bd2e67, the merge I pushed last time. Classification is unsettled. I asked again whether this is a bug fix or an enhancement, because the head changed after the last classification. Two models answered separately and disagreed. I (Claude Opus 5.5) called it a Why it conflicts. #16756 deleted Competing fixes are unchanged. #13044 and #13094 (for #13037) are still open. They fix the same Waiting on the maintainer: to settle whether this is a bug fix and whether |
The bug
sudo visudoandsudoeditsilently throw away your edits if your Omarchy default editor is a graphical one.sudo never lets the editor touch the real file. It copies the file to a temp path, runs the editor, waits for the editor to exit, then keeps whatever is on disk. That last step only works if the editor command stays running until you close it.
default/bash/envssetsSUDO_EDITOR="$EDITOR", which isomarchy-launch-editor --inline. That script only runs inline fornvim|vim|nano|micro|hx|helix|fresh; everything else takes the*)branch and runsexec setsid uwsm-app -- "$editor"— detached, returns instantly. So visudo sees an editor that closed without changing anything, printsunchanged, and deletes the temp copy. The editor window then opens on a file that is already gone.Of the eight editors
omarchy default editoroffers, five detach:code,cursor,zed,sublime_text,emacs. Onlynvim,vim,helixblock — and sincenvimis the default, the bug stays hidden.Measured on a 4.0.0.alpha machine,
visudoon a temp sudoers file with a stubbeduwsm-app:Zero seconds,
unchanged, edit gone.The fix
A
--sudomode onomarchy-launch-editorthat never detaches: a terminal editor runs in place, anything else falls back tonvim. Falling back beats honouring the choice here — the alternative is running a full graphical IDE as root over an elevated Wayland connection.default/bash/envsthen pointsSUDO_EDITORat it, but only when Omarchy is the one supplyingEDITOR:An
EDITORthe user exported themselves is left to them, and an explicitSUDO_EDITORstill wins over both. The--inlineand windowed paths are untouched, so normal editor launching is unchanged.Verified
Same scenario as the repro — default editor
code,SUDO_EDITORtaken from the realdefault/bash/envs:It now blocks for the full timeout and had to be killed, and
uwsm-appis never called. Before, the same run finished in 0s with the edit discarded.Tests
test/shell.d/launch-editor-sudo-test.sh(new) — reads the editor list offomarchy-default-editorso an editor added there is covered without a second edit, and asserts--sudonever reachessetsid,uwsm-app, oromarchy-launch-tui(a separate terminal window returns just as early). Also pins the windowed and--inlinepaths so this does not change ordinary launching.test/shell.d/editor-env-test.sh— updated for the newSUDO_EDITOR, plus cases for a user-setEDITORand an explicitSUDO_EDITOR.test/clipasses in full.test/shell: 216 of 222 files pass; the 6 failures (ascii,branding-about-animation,config,legacy-power-udev-rules-migration,snapper,unowned-system-paths) fail identically on a cleanquattro.Independent of #9500, which fixes a different editor bug (
visudoas root finding no editor at all). No file overlap.🤖 Generated with Claude Code