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

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.

2 participants