defunkt/gist — pull request #189 by jasonkarns (2014-11-06 16:11:38+00:00)
Title: XDG directory compliance for auth token

Follow the XDG directory spec for storing authentication tokens.

closes #179
alternate implementation to #158

Decision tree:

| XDG token | ~ token | directory used |
| ---- | ---- | ---- |
| does not exist | exists | ~ |
| exists | does not exist | XDG |
| exists | exists | XDG |
| does not exist | does not exist | XDG |

So for existing users with existing auth tokens in `~`, nothing will change. It will continue to use the token files from `$HOME`. For users who wish to migrate to the XDG directories, the existing tokens would need to be moved/copied to the XDG directory (either `$XDG_CACHE_HOME/gist` or `$HOME/.cache/gist`). For new users (or users without existing tokens), the XDG directory structure is used as the preferred location. The only weird edge case is for users who have tokens in *both* `$HOME` and XDG locations (for whatever weird reason). In that scenario, the XDG tokens are used.

There is a wrinkle that still exists. Since the directory location for reading/writing branches off whether the specific token file exists (including the GITHUB_URL suffix), it is possible to end up with `~/.gist` and `~/.cache/gist/auth_token.somecorp.github.com` or vice versa. This is clearly not desirable. So I have plans to change the decision tree to branch based on whether `$XDG_CACHE_HOME/gist` and `~/.gist*` exist. This way we'll be deciding based on the existence of the gist *directory* under `$XDG_CACHE_HOME` as well as whether *any* `.gist*` file exists in `$HOME`; not a specific token file in particular. This will ensure that the multiple gist tokens are always stored together, whether they be in `$HOME` or `$XDG_CACHE_HOME`.

Feedback?

# not ready to merge