common-fate / granted

The easiest way to access your cloud.
https://granted.dev
MIT License
956 stars 90 forks source link

feature request: allow saving shell completions to custom directory #595

Open jay-aye-see-kay opened 5 months ago

jay-aye-see-kay commented 5 months ago

Background

I'd like to install shell completions to a custom directory. AFAIK the only way to generate them is with granted completion --shell <shell> which saves them to a hard coded file path.

I tried changing the $HOME and $XDG_CONFIG variables but user.Current().HomeDir ignores those (used here: https://github.com/common-fate/granted/blob/bbc5266/pkg/granted/completion.go#L54-L65). os.UserHomeDir() does respect $HOME which would allow me to hack around this a bit, but I'd rather a more flexible solution below instead.

Suggested fix

Allow granted completion to take a flag --stdout that prints the shell config to stdout instead of writing it to a file.

I'd be happy to open a PR implementing this (or something similar) if you're open to it.

Additional info; my specific use case

This info isn't directly related to the feature request, I'm just providing more context for interest's sake. The features suggested should make granted more flexible in general, not just for my setup.

I've installed granted via nix and would like to configure completions using home-manager. To make that work I want to be able to generate completions at install time and save them to an arbitrary location in the nix store.