Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #29: Parse ~/.config/user-dirs.dirs file #42

Closed
wants to merge 1 commit into from

Conversation

ax1036
Copy link

@ax1036 ax1036 commented Oct 19, 2022

Read ~/.config/user-dirs.dirs if exist, inject in env var if not already present

Test TestDefaultUserDirs will fail if localized file found.

Workaround without this merge:

func LoadlinuxXDG() {
	var (
		homeDir string
		err     error
	)

	if homeDir, err = os.UserHomeDir(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	userDirFile := path.Join(homeDir, ".config/user-dirs.dirs")

	if _, err = os.Stat(userDirFile); err != nil {
		return
	}

	cfg, err := ini.Load(userDirFile)
	if err != nil {
		return
	}

	// Load xdg env
	for _, key := range cfg.Section("").Keys() {
		value := strings.Replace(key.Value(), "$HOME", homeDir, 1)
		os.Setenv(key.Name(), value)
	}

	xdg.Reload()
}

@the-solipsist
Copy link

Hi, is this commit good enough to be merged?

@adrg
Copy link
Owner

adrg commented Oct 16, 2023

Hi, is this commit good enough to be merged?

Hi @the-solipsist. Sorry for the late response. I think the external workaround is sufficiently easy to apply.

Thing is, I don't have external package dependencies right now and I would rather keep it that way. I will probably parse user-dirs.dirs internally at some point in the future. I don't exactly know when that will be. Depends on my free time, which is not much at the moment.

@adrg
Copy link
Owner

adrg commented Jul 8, 2024

Thank you for the PR.
Superseded by #87. Closing this one.

@adrg adrg closed this Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants