-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
base: master
Are you sure you want to change the base?
Conversation
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
configHome := os.Getenv("XDG_CONFIG_HOME") | ||
if configHome == "" { | ||
configHome = filepath.Join(os.Getenv("HOME"), ".config") | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
I'd love to see his PR merged. Any way of pre-configuring the default output would be of interest. Ideally, a |
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) |
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. |
I found myself wanting for a default
-only local
, so I hacked together a good olddufrc
support – default commandline options can be stored in there as so:and unless a
-norc
option is passed in, these options will get included when runningduf
.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 confuseflag
, 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:
duf
support any?)