[Linux] Move the .cursorless folder away from the home directory
Problem: Hi, I am using talon with cursorless to program in a VS Codium flatpak installation. Works great 👍. Now the only thing that's bothering me is the location of the .cursorless directory in the home folder. To be more in line with the XDG Base Directory Specifications.
Solution: I would recommend moving the folder to "~/.config/cursorless" or "~/.cache/cursorless". I don't know which one would be best here, as I don't really get what purpose that folder serves. If you want to be really fancy you could even read $XDG_CONFIG_HOME or $XDG_CACHE_HOME environment variable respectively to determine where to put it that folder, but i am not even asking for that much.
Implementation: As far is I could tell by looking at the code, you are using that directory only once on Linux. And that is here: https://github.com/cursorless-dev/cursorless/blob/bfc4d8497c65787c3b4510f11745cb6baf6061bf/cursorless-talon/src/spoken_forms_output.py#L7 Take that with a grain of salt tho, as I only looked at the "cursorless-talon/src" folder. You could change that to something like that:
from talon import app
import os #is this needed or can talon also read environment variables?
from pathlib import Path
def config_dir_linux():
xdg_config_home = os.getenv("XDG_CONFIG_HOME")
if xdg_config_home:
# If XDG_CONFIG_HOME is set, use that path
config_path = Path(xdg_config_home)
else:
# Otherwise, fall back to the default ~/.config
config_path = Path.home() / ".config"
return config_path / "cursorless"
if app.platform == "linux":
SPOKEN_FORMS_OUTPUT_PATH = config_dir_linux() / "state.json"
else:
SPOKEN_FORMS_OUTPUT_PATH = Path.home() / ".cursorless" / "state.json"
I hope that makes changing this relatively easy.
Thanks you for your time and effort.
I think this is just used to share state from Talon to VSCode? XDG_STATE_HOME would be significantly more appropriate than XDG_CONFIG_HOME; this file is never used as the source of truth for the user's config.
Oh, okay. Then put it under XDG_STATE_HOME or XDG_CACHE_HOME. I dont mind changing that. I only care about it not being in the home directory. I also found a great source that shows the efforts the linux community goes through to remove dot files from the home directory: https://wiki.archlinux.org/title/XDG_Base_Directory
A common solution is also to provide some environment variable, like e.g. CURSORLESS_CACHE where the user can store the directory they want that folder to go. Many programs solve it like that.