Parse a dufrc file to allow for default settings
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:
- [x] docs (postponed until feedback comes in)
- [x] paths for non-XDG platforms (does
dufsupport any?)
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.
I'd love to see his PR merged. Any way of pre-configuring the default output would be of interest. Ideally, a
dufrcfile 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)
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.
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.
Switched it over to go-app-paths, done the docs (manpage and README).
Bump. Is there anything blocking this still?
Bump. Is there anything blocking this still?
Looks mostly fine, really. Will get to this one soon. Maybe a slightly different format (simple key/value style) might be a bit user-friendlier? Will rebase when I'm done merging my current changes.
You can use whatever format you consider the best. But just a translation of the command line into the file as it is proposed seems easy enough, as you don't have to learn a new format, just cut&paste the command line you liked (and change spaces by new lines, that's the most confusing part).
(and change spaces by new lines, that's the most confusing part).
I wish you wouldn't have to do that, but that'd (I think?) require introducing a CLI argument parser, which makes things quite a bit more complex.