test: Correctly fall back to EDITOR or VISUAL env vars
This commit is contained in:
parent
620a7bc401
commit
46135f9325
2 changed files with 21 additions and 2 deletions
|
|
@ -107,3 +107,16 @@ class TestTConf:
|
||||||
def test_default_notes_sub_dir(self):
|
def test_default_notes_sub_dir(self):
|
||||||
cfg = TConf.from_dict({"task_data": "~/my/tasks", "task_id": 0})
|
cfg = TConf.from_dict({"task_data": "~/my/tasks", "task_id": 0})
|
||||||
assert cfg.notes_dir == Path("~/my/tasks/notes").expanduser()
|
assert cfg.notes_dir == Path("~/my/tasks/notes").expanduser()
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"env,expected",
|
||||||
|
[
|
||||||
|
({"EDITOR": "vim"}, "vim"),
|
||||||
|
({"VISUAL": "emacs", "EDITOR": ""}, "emacs"),
|
||||||
|
({"VISUAL": "nvim", "EDITOR": "notepad"}, "notepad"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_editor_env_resolution(isolate_env, monkeypatch, env, expected):
|
||||||
|
for k, v in env.items():
|
||||||
|
monkeypatch.setenv(k, v)
|
||||||
|
assert TConf(0).notes_editor == expected
|
||||||
|
|
|
||||||
10
topen.py
10
topen.py
|
|
@ -188,7 +188,7 @@ OPTIONS: dict[str, Opt] = {
|
||||||
("--editor",),
|
("--editor",),
|
||||||
"TOPEN_NOTES_EDITOR",
|
"TOPEN_NOTES_EDITOR",
|
||||||
"notes.editor",
|
"notes.editor",
|
||||||
default=os.getenv("EDITOR") or os.getenv("VISUAL") or "nano",
|
default="nano",
|
||||||
metavar="CMD",
|
metavar="CMD",
|
||||||
help_text="Program to open note files with",
|
help_text="Program to open note files with",
|
||||||
),
|
),
|
||||||
|
|
@ -225,7 +225,7 @@ class TConf:
|
||||||
"""The extension of note files."""
|
"""The extension of note files."""
|
||||||
notes_annot: str = OPTIONS["notes_annot"].default
|
notes_annot: str = OPTIONS["notes_annot"].default
|
||||||
"""The annotation to add to taskwarrior tasks with notes."""
|
"""The annotation to add to taskwarrior tasks with notes."""
|
||||||
notes_editor: str = OPTIONS["notes_editor"].default
|
notes_editor: str = "" # added in post-init
|
||||||
"""The editor to open note files with."""
|
"""The editor to open note files with."""
|
||||||
notes_quiet: bool = OPTIONS["notes_quiet"].default
|
notes_quiet: bool = OPTIONS["notes_quiet"].default
|
||||||
"""If set topen will give no feedback on note editing."""
|
"""If set topen will give no feedback on note editing."""
|
||||||
|
|
@ -236,6 +236,12 @@ class TConf:
|
||||||
if self.notes_dir == NON_EXISTENT_PATH:
|
if self.notes_dir == NON_EXISTENT_PATH:
|
||||||
self.notes_dir = self._default_notes_dir()
|
self.notes_dir = self._default_notes_dir()
|
||||||
self.notes_dir = _real_path(self.notes_dir)
|
self.notes_dir = _real_path(self.notes_dir)
|
||||||
|
if not self.notes_editor:
|
||||||
|
self.notes_editor = (
|
||||||
|
os.getenv("EDITOR")
|
||||||
|
or os.getenv("VISUAL")
|
||||||
|
or OPTIONS["notes_editor"].default
|
||||||
|
)
|
||||||
|
|
||||||
def __or__(self, other: Any, /) -> Self:
|
def __or__(self, other: Any, /) -> Self:
|
||||||
return self.__class__(**asdict(self) | asdict(other))
|
return self.__class__(**asdict(self) | asdict(other))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue