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

Parse a dufrc file to allow for default settings #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tadzik
Copy link

@tadzik tadzik commented Dec 28, 2024

I found myself wanting for a default -only local, so I hacked together a good old dufrc support – default commandline options can be stored in there as so:

-only
local

and unless a -norc option is passed in, these options will get included when running duf.

flag.Parse() doesn't allow for passing in a string, so we modify os.Args based on the contents of XDG_CONFIG_HOME/dufrc.

I'm not sure how flag.Parse() would react to being called multiple times, and how that'd affect default options – and didn't want to rely on testing it, since if it's not in the docs then it might as well change in the future – so -norc is added to options to not confuse flag, but it's checked for manually to avoid double-Parse().

Each arg is on the separate line – I'm not sure if Go has anything for parsing shell quotes, I didn't want to deal with that and/or introduce an additional dependency.

TODO:

  • docs (postponed until feedback comes in)
  • paths for non-XDG platforms (does duf support any?)

flag.Parse() doesn't allow for passing in a string,
so we modify os.Args based on the contents of XDG_CONFIG_HOME/dufrc.
main.go Outdated
Comment on lines 150 to 153
configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome == "" {
configHome = filepath.Join(os.Getenv("HOME"), ".config")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could consider os.UserConfigDir

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a much better choice; thanks! Changed in 7b0fd48

@Poshi
Copy link

Poshi commented Feb 13, 2025

I'd love to see his PR merged. Any way of pre-configuring the default output would be of interest. Ideally, a dufrc file and environment variables. But at least one!
Thanks for your effort in this PR! Let's see if it gets merged and released some day.

@tadzik
Copy link
Author

tadzik commented Feb 13, 2025

I'd love to see his PR merged. Any way of pre-configuring the default output would be of interest. Ideally, a dufrc file and environment variables. But at least one! Thanks for your effort in this PR! Let's see if it gets merged and released some day.

Now that it's approved I guess it's actually up to me to follow-up with documentation :)

(Unless someone else chimes in? I'm terrible at this)

@muesli
Copy link
Owner

muesli commented Feb 13, 2025

It's probably a good idea to stick to XDG standards for the config file location. Check out https://github.com/muesli/go-app-paths.

@tadzik
Copy link
Author

tadzik commented Feb 13, 2025

It's probably a good idea to stick to XDG standards for the config file location. Check out https://github.com/muesli/go-app-paths.

Isn't that what https://pkg.go.dev/os#UserConfigDir does?

Ah, not quite – doesn't fallback to /etc and all that. go-app-paths sounds like a sensible solution.

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.

4 participants