zu1k / nali

An offline tool for querying IP geographic information and CDN provider. 一个查询IP地理信息和CDN服务提供商的离线终端工具.
https://github.com/zu1k/nali
MIT License
3.76k stars 340 forks source link

Use $XDG_CONFIG_HOME on Linux #138

Closed rapiz1 closed 1 year ago

rapiz1 commented 1 year ago

Thanks for your great work! I encountered this project when I was using skk's nail-cli and wanted to switch to geoip2. It's a good enhancement. However, I noted nali still uses the config directory in a way only legacy software does.

~/.nali is a non-standard directory for configurations on Linux. The best practice is $XDG_CONFIG_HOME/nali. The main drawback for non-standard configuration directory is that it messes up with users' home directory and is not easy to organize.

To keep nali backward-compatible as well as conform with the XDG standards, I propose following solution:

  1. Support $XDG_CONFIG_HOME/nali as a config directory. When nali stars, it scans ~/.nali, $XDG_CONFIG_HOME/nali for configs and use the first hit.
  2. If none of above directory exists, create $XDG_CONFIG_HOME/nali with the default configuration.

I understand nali works on multiple platforms besides Linux. I don't know much about other platforms and they may also have similar issues.

zu1k commented 1 year ago

Good suggestion, nali's configuration file and ip database directory really need to be more standardized.

But I've been busy recently, if you can pull a request for this I would be very grateful.

zu1k commented 1 year ago

https://github.com/zu1k/nali/blob/60bab5e13b22056bb3caf36d632f8347a5f8dd8c/internal/constant/path.go#L15

For existing versions of nali, you can change the directory via the environment variable NALI_HOME.

zu1k commented 1 year ago

This was modified in version v0.6.0