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.
This commit is contained in:
Marty Oehme 2025-04-08 20:35:33 +02:00
parent 5976651a26
commit ee4f3781f8
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -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."""