Repository navigation
Keep the sudo editor on one that blocks #9503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,17 @@ | ||
| # Editor used by CLI | ||
| export EDITOR="${EDITOR:-omarchy-launch-editor --inline}" | ||
| export SUDO_EDITOR="$EDITOR" | ||
|
|
||
| # sudo keeps whatever is on disk once the editor exits, so an editor that | ||
| # detaches -- every graphical one omarchy-default-editor offers -- reads as | ||
| # "closed without changing anything" and sudoedit and visudo throw the edit | ||
| # away with no error. Send the Omarchy default through --sudo, which stays on a | ||
| # 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}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a new shell inherits the old Omarchy value |
||
| else | ||
| export SUDO_EDITOR="${SUDO_EDITOR:-$EDITOR}" | ||
| fi | ||
|
|
||
| # Used by terminal programs (like gh) to open URLs detached from the terminal | ||
| # process tree. Shell-scoped on purpose: exporting BROWSER session-wide makes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(dirname "$0")/base-test.sh" | ||
|
|
||
| launcher="$ROOT/bin/omarchy-launch-editor" | ||
| chooser="$ROOT/bin/omarchy-default-editor" | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'rm -rf "$test_tmp"' EXIT | ||
|
|
||
| stub_bin="$test_tmp/bin" | ||
| home="$test_tmp/home" | ||
| mkdir -p "$stub_bin" "$home/.local/state/omarchy/defaults" | ||
|
|
||
| # Every command the launcher can hand the file to logs its own argv, so the | ||
| # assertions read the process that would actually have run. | ||
| for stub in nvim vim nano micro hx helix fresh code cursor zeditor sublime_text \ | ||
| emacs setsid uwsm-app omarchy-launch-tui; do | ||
| cat >"$stub_bin/$stub" <<SH | ||
| #!/bin/bash | ||
| printf '%s %s\n' "$stub" "\$*" >>"\$LAUNCH_LOG" | ||
| SH | ||
| chmod +x "$stub_bin/$stub" | ||
| done | ||
|
|
||
| # Without this the launcher falls back to nvim for every editor and the run | ||
| # proves nothing about the editor that was chosen. | ||
| cat >"$stub_bin/omarchy-cmd-present" <<'SH' | ||
| #!/bin/bash | ||
| exit 0 | ||
| SH | ||
| chmod +x "$stub_bin/omarchy-cmd-present" | ||
|
|
||
| launch_with() { | ||
| local editor="$1" | ||
| shift | ||
|
|
||
| printf '%s\n' "$editor" >"$home/.local/state/omarchy/defaults/editor" | ||
| : >"$test_tmp/log" | ||
| LAUNCH_LOG="$test_tmp/log" HOME="$home" PATH="$stub_bin:$PATH" \ | ||
| bash "$launcher" "$@" /etc/sudoers.tmp >/dev/null 2>&1 || true | ||
| cat "$test_tmp/log" | ||
| } | ||
|
|
||
| # The editors the menu can actually put in that state file, read off the | ||
| # chooser so an editor added there is covered here without a second edit. | ||
| mapfile -t editors < <(grep -oE 'editor="[a-z_]+"' "$chooser" | cut -d'"' -f2 | sort -u) | ||
| ((${#editors[@]} >= 8)) || | ||
| fail "the chooser's editor list was read" "got: ${editors[*]}" | ||
|
|
||
| for editor in "${editors[@]}"; do | ||
| launched=$(launch_with "$editor" --sudo) | ||
|
|
||
| [[ $launched == *"/etc/sudoers.tmp"* ]] || | ||
| fail "--sudo hands $editor the file to edit" "got: $launched" | ||
|
|
||
| # setsid and uwsm-app both return before the editor is done, which is what | ||
| # loses the edit. Neither belongs anywhere on the sudo path. | ||
| [[ $launched != *"setsid"* && $launched != *"uwsm-app"* ]] || | ||
| fail "--sudo does not detach the editor for $editor" "got: $launched" | ||
|
|
||
| # omarchy-launch-tui opens a separate terminal window and returns, so it is | ||
| # no better here than detaching outright. | ||
| [[ $launched != *"omarchy-launch-tui"* ]] || | ||
| fail "--sudo does not hand $editor to a separate terminal" "got: $launched" | ||
| done | ||
|
|
||
| pass "--sudo blocks for every editor the chooser offers" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test reports that 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! |
||
|
|
||
| # The windowed and inline paths are unchanged: a graphical editor still gets | ||
| # detached when it is not sudo asking. | ||
| windowed=$(launch_with code) | ||
| [[ $windowed == "setsid uwsm-app -- code -- /etc/sudoers.tmp" ]] || | ||
| fail "a graphical editor is still detached when launched windowed" "got: $windowed" | ||
|
|
||
| windowed=$(launch_with nvim) | ||
| [[ $windowed == "omarchy-launch-tui nvim -- /etc/sudoers.tmp" ]] || | ||
| fail "a terminal editor is still opened in a terminal when launched windowed" "got: $windowed" | ||
|
|
||
| inline=$(launch_with nvim --inline) | ||
| [[ $inline == "nvim -- /etc/sudoers.tmp" ]] || | ||
| fail "--inline still runs a terminal editor in place" "got: $inline" | ||
|
|
||
| pass "the windowed and inline paths are unchanged" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a graphical editor is selected but Neovim has been removed or is unavailable on PATH,
--sudorunsnvimwithout checking for it. The earlier availability check only tests the selected graphical editor, so sudoedit and visudo cannot open the temporary file.