duf icon indicating copy to clipboard operation
duf copied to clipboard

Parse a dufrc file to allow for default settings

Open tadzik opened this issue 1 year ago • 9 comments

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 duf support any?)

tadzik avatar Dec 28 '24 11:12 tadzik

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.

Poshi avatar Feb 13 '25 10:02 Poshi

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)

tadzik avatar Feb 13 '25 10:02 tadzik

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.

muesli avatar Feb 13 '25 10:02 muesli

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.

tadzik avatar Feb 13 '25 10:02 tadzik

Switched it over to go-app-paths, done the docs (manpage and README).

tadzik avatar May 05 '25 13:05 tadzik

Bump. Is there anything blocking this still?

tadzik avatar Jun 27 '25 10:06 tadzik

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.

muesli avatar Sep 01 '25 04:09 muesli

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).

Poshi avatar Sep 01 '25 10:09 Poshi

(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.

tadzik avatar Sep 01 '25 10:09 tadzik