hnarayanan / shpotify

A command-line interface to Spotify.
https://harishnarayanan.org/projects/
2.01k stars 153 forks source link

Add XDG Base Directory support #161

Open pbaudoux opened 2 years ago

pbaudoux commented 2 years ago

This PR adds support for XDG Base Directory Specification.

Configuration file should be stored in $XDG_CONFIG_HOME if the variable is set and $HOME/.config if not. For backward compatibility reason, if a dotfile already exist in $HOME, then it is used.

More information here: https://wiki.archlinux.org/title/XDG_Base_Directory

hnarayanan commented 2 years ago

Thank you for this. Could you possibly rework this PR to be more In line with the description you have above? i.e.

If $XDG_CONFIG_HOME is set:
   use it to find the file
else:
   do what was happening before
pbaudoux commented 2 years ago

Hi,

Thanks for your reply.

From the specification:

XDG_CONFIG_HOME Where user-specific configurations should be written (analogous to /etc). Should default to $HOME/.config.

So the behavior should be:

If $XDG_CONFIG_HOME is set:
   use it to find the file
else:
   use $HOME/.config

The idea is to centralize all config files in a single folder, by default the .config folder, and avoid hundreds of wild dotfiles in $HOME.

For backward compatibility purpose, I first check if the dotfile is present in $HOME (i.e. the user already used a previous version of shpotify), making the full pseudo-code:

If $HOME/.shpotify.cfg exist:
   use it
else if $XDG_CONFIG_HOME is set:
   use it 
else:
   use $HOME/.config (should be the case for most users)

I hope this brings some clarity to the PR.

samuelmasuy commented 1 year ago

I tried to introduce a way to override where shpotify finds its config file in #142, this could be less invasive, where it would be the responsibility of the end-user to say that SHPOTIFY_CONFIG_FILE=$XDG_CONFIG_HOME/shpotify/shpotify.cfg for example.