Open lucasew opened 1 year ago
This is what I get when I try to install the completions in NixOs (this should be done when installing Terraform via package manager, not by the user IMO):
$ terraform -install-autocomplete
Error executing CLI: 1 error occurred:
* open /home/h/.bashrc: permission denied
Thanks for the request!
Autocompletion is handed off entirely to mitchellh/cli. The proposal makes sense to me, though we'd likely want to introduce it in a backwards-compatible way with an additional arg of some sort.
I suggest opening an issue at https://github.com/mitchellh/cli/issues - Mitchell is a Nix user so I'm sure he'll be sympathetic.
And mitchellh/cli hands off completion to posener/complete.
And posener/complete hardcodes where it writes the scripts. It would be handy to be able to write to stdout
, so we can redirect to any file we want.
The completion scripts only set COMP_LINE
and invoke the command so they normally don't change between versions.
Makes it pretty simple to bridge for other shells as well.
For now you could just generate them once and add them to the package.
While I think this would be nice, as this seems to be a general pattern where the command can generate the completion scripts for each shell (ala cobra), the completion script is so minimal for the hashicorp CLI tools because of this comments (https://github.com/hashicorp/terraform/issues/32611#issuecomment-1520192253) statement.
Nix package just generates this scripts line.
Terraform Version
Use Cases
Attempted Solutions
terraform -install-autocomplete
Imperative approach. Fails if you use home-manager because ~/.bashrc is a symlink to a file in the nix store, that is read only.HOME=/somewhere/else terraform -install-autocomplete
Terraform ignores the environment variable and tries to write ~/.bashrc anyway.Proposal
The same approach rclone uses to expose completions, ex:
rclone completion bash
generate bash completion and output to stdoutReferences
28788