Skip to content

Improved XDG basedir spec compliance #554

Description

@jasonkarns

Describe the bug

$ gh --version
gh version 0.5.7 (2020-02-20)
https://github.com/cli/cli/releases/tag/v0.5.7

gh appears to conform to the XDG basedir spec by writing to ~/.config/gh. However, it does not respect XDG_CONFIG_HOME as it should. ~/.config is the default value for XDG_CONFIG_HOME, but should only be used if XDG_CONFIG_HOME itself is unset. If it is set, it should be respected.

Steps to reproduce the behavior

  1. rm -rf ~/.config/gh (or rename)
  2. export XDG_CONFIG_HOME=$(mktemp -d) (configure a custom config-home)
  3. gh issue list run a command to trigger authentication
  4. ls ~/.config/gh note that gh was re-created under ~/.config instead of the temp directory
  5. ls $XDG_CONFIG_HOME note that nothing was written to XDG_CONFIG_HOME; this is where gh/config.yml should have been written.

Expected vs actual behavior

Conformance to the XDG spec requires that the XDG_CONFIG_HOME variable be respected for where to write user configuration files. gh is writing to ~/.config but not respecting XDG_CONFIG_HOME when it is set.

Activity

  1. mislav commented on Feb 26, 2020

    @mislav
    Contributor

    Thank you! I definitely want to support the XDG basedir spec before we reach stable release. 👍

  2. jasonkarns commented on Feb 26, 2020

    @jasonkarns
    Author

    I also noticed that the files within .config/gh aren't "config" (at least, not in the sense that I'd expect people to be able to version in dotfiles repo or anything). Both the oauth token in config.yml and the entire state.yml file should probably be saved in XDG_DATA_HOME. Should that just be noted here or as a separate issue? (It's all the same general concern, but I'd honestly expect them to be implemented as separate PRs. But also understand it's still early days for the project and having a hundred issues isn't helpful. 😸 )

  3. severen commented on Mar 6, 2020

    @severen

    I'm very pleased to see that adding support is a goal for a stable release!

    I also noticed that the files within .config/gh aren't "config" (at least, not in the sense that I'd expect people to be able to version in dotfiles repo or anything).

    This is a very important and often overlooked part of the entire value proposition of the XDG basedir spec. What resides in $XDG_CONFIG_HOME should only be configuration files in the purest sense, and be ideally a human readable, plain text file format that is easily edited by hand and stable (in that, if I invoke gh, it won't modify the file unless explicitly asked).

    Apologies if I've come across a bit strong there, but there are a thousand and one programs that violate that and nullify half the point of the spec (see: Chromium and everything derived from it).

  4. mislav commented on Mar 6, 2020

    @mislav
    Contributor

    Apologies if I've come across a bit strong there, but there a thousand and one programs that violate that and nullify half the point of the spec

    @severen Your opinions about XDG certainly seem strongly held, but I value you arguing for them because that gives us useful pointers about what we should consider when we do implement it.

    @jasonkarns I agree that our config file right now isn't really config. We might be able to avoid storing one's username, because we know your user handle as soon as we authenticate with the stored token, and we might be able to avoid storing the token in a file in the first place if we implement storing it in your OS's keyring.

    In the future, though, GitHub CLI will probably have some actual configuration options, and we will store these under XDG_CONFIG_HOME, and I'm guessing that we can store "data" files (such as the date of the last lookup of the update notifier) under XDG_DATA_HOME.

  5. changed the title [-]Does not respect XDG_CONFIG_HOME[/-] [+]Improved XDG basedir spec compliance[/+] on Mar 6, 2020
  6. added
    priority-3Affects a small number of users or is largely cosmetic
    on Sep 29, 2020
  7. vilmibm commented on Nov 24, 2020

    @vilmibm
    Contributor

    I'd like to revisit this conversation, but I think that sets off a connected conversation about host-specific configuration.

    It sounds like we should stop putting host-specific config into hosts.yml so that hosts.yml can be moved into XDG_DATA_HOME.

    In general, I think the host/global config concept can be improved or at least better edified; that will make it easier to consider this issue.

    @mislav @samcoe thoughts?

  8. mislav commented on Nov 24, 2020

    @mislav
    Contributor

    I'm not sure I understand exactly what you are proposing to do with hosts.yml, but I'm going to outline my general thoughts.

    In a future where we support the XDG basedir spec (I'm sorry @jasonkarns @severen that this didn't make it into our v1.0), I do not feel strongly about hosts.yml being moved to XDG_DATA_HOME. After all, most of what hosts.yml holds is host-specific configuration, and as such I feel like it belongs to XDG_CONFIG_HOME.

    We can weigh the pros vs. cons of storing OAuth tokens in this file, or in DATA vs CONFIG directory, but I believe that ultimately we should move these tokens out of plain text files anyway: #449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingconfigpriority-3Affects a small number of users or is largely cosmetic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions