From ee4f3781f88799d72247980e42b846cbc7ef5bdd Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 8 Apr 2025 20:35:33 +0200 Subject: [PATCH] feat: Use xdg location or home dir taskrc if it exists The preference structure goes highest to lowest: 1. ~/.taskrc 2. $XDG_CONFIG_HOME/task/taskrc 3. ~/.config/task/taskrc Uses first file found. --- topen.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/topen.py b/topen.py index 9de9da5..274b84f 100755 --- a/topen.py +++ b/topen.py @@ -118,10 +118,29 @@ class TConf: task_id: int """The id (or uuid) of the task to edit a note for.""" - task_rc: Path = Path("~/.config/task/taskrc") - """The path to the taskwarrior taskrc file.""" + task_rc: Path + _task_rc: Path | None = field(init=False, repr=False, default=None) + """The path to the taskwarrior taskrc file. Can be absolute or relative to cwd.""" + + @property + def task_rc(self) -> Path: + if self._task_rc: + return self._task_rc + elif _real_path("~/.taskrc").exists(): + return _real_path("~/.taskrc") + elif _real_path("$XDG_CONFIG_HOME/task/taskrc").exists(): + return _real_path("$XDG_CONFIG_HOME/task/taskrc") + else: + return _real_path("~/.config/task/taskrc") + + @task_rc.setter + def task_rc(self, value: Path | property | None): + if type(value) is property: + value = TConf._notes_dir + self._task_rc = cast(Path, value) + task_data: Path = Path("~/.task") - """The path to the taskwarrior data directory.""" + """The path to the taskwarrior data directory. Can be absolute or relative to cwd.""" notes_dir: Path """The path to the notes directory."""