roamer
roamer copied to clipboard
.roamerrc file instead of environment variables
Looks like the values to load from .roamerrc are just: ROAMER_DATA_PATH and ROAMER_EDITOR. They’re used in three places: roamer/constant.py, roamer/file_edit.py, and tests/test_integration.py. I’d probably move the editor selection into the constants file too. Thoughts?
Correct those are the two values that need to be moved. Yes the editor selection belongs in the constants file. Good catch!
Imho you should consider xdg compliance (https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). Not sure how hard that is, though :)
Here's a general outline of the direction I'd like to take. I want this to be a collaboration so please comment if you have a differing opinion.
We should follow the XDG Specification. https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
We can add this package as a dependency... https://github.com/srstevenson/xdg
If it's helpful we can loosely base this the way Ranger does it... https://github.com/ranger/ranger/blob/d861ba27b25a32aacb845eb33b6c9ce95cb33356/ranger/ext/rifle.py#L383-L407
For the actual layout of the config file my preference would be to follow INI file structure as that seems to be the most widely adopted. I do think forcing users to include a [section] is crufty for a tool like roamer.
.roamerrc example...
ROAMER_EDITOR=emacs
# comment line
OPTIONS=--skip-approval,--future-other-flag
We can use configparser library to get most of logic but we'll need to work around the expectation of sections.
https://stackoverflow.com/questions/2885190/using-pythons-configparser-to-read-a-file-without-section-name
Yeah, following XDG Specification is great, but I think that use additional package is overkill for the ~10 lines.
I see two options if config file does not exists at XDG dirs:
- create it there
- check somewhere else, for example here:
~/.config/roamer
As about .rc file itself -- at least for now It would be enough to have plain text file, and parse it without libs.
@abaldwin88 so what about Windows ~~~and what to do if there is no $XDG_CONFIG_HOME var~~~?
Update
$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
Yep the spec has a default location to use when the var isn't set.
Windows is only supported in roamer using the ubuntu subsystem. So using $HOME/.config should work fine. I have a windows box I'll test it on before merging.
Add dependencies at your discretion. If you can write something simple that covers our bases then let's add it directly.
@abaldwin88 Just want to say that I've got pretty busy days and that's why I didn't implement it yet. But I'm looking forward for doing it.