Skip to content

Honor PSQL_EDITOR when opening the external editor - #1616

Merged
dbaty merged 1 commit into
dbcli:mainfrom
ChrisJr404:honor-psql-editor
Aug 18, 2026
Merged

Honor PSQL_EDITOR when opening the external editor#1616
dbaty merged 1 commit into
dbcli:mainfrom
ChrisJr404:honor-psql-editor

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Description

Closes #1398. psql lets you point \e at a dedicated editor via PSQL_EDITOR so it doesn't have to be whatever EDITOR/VISUAL you use everywhere else, and pgcli didn't respect it.

pgcli hands editing off to pgspecial.open_external_editor, which calls click.edit() and lets click resolve the editor from VISUAL/EDITOR. That function already takes an editor= override, we just weren't passing anything. I added a small get_editor() helper that mirrors psql's lookup order (PSQL_EDITOR, then EDITOR, then VISUAL) and threaded its result through both editor call sites (\e/\ev/\ef and \ne). When none of those are set it returns None, which keeps click's existing platform-default behaviour, so nobody who wasn't setting PSQL_EDITOR sees a change.

Test-wise I added test_get_editor_precedence asserting PSQL_EDITOR wins over EDITOR/VISUAL, that it falls back to EDITOR then VISUAL, and returns None when the environment is empty. Ran python -m pytest tests/test_main.py -k "editor or named_query" (2 passed) and the full tests/test_main.py (60 passed, 10 db skips). ruff check and ruff format --diff are both clean.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected.
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@dbaty dbaty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you! :)

@dbaty
dbaty merged commit 17135da into dbcli:main Aug 18, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Respect PSQL_EDITOR environment variable

2 participants