snapcrafters / terraform

Unofficial snap package for Hashicorp Terraform
https://snapcraft.io/terraform
Mozilla Public License 2.0
0 stars 3 forks source link

[Enhancement]: enable bash completion #113

Open boukendesho opened 1 week ago

boukendesho commented 1 week ago

What changes would you like?

Is it possible to enable bash completion ?

Any extra information?

~I've tried terraform -install-autocomplete but don't work.~

And i found this bash completion script from gist

boukendesho commented 1 week ago

Sorry , terraform -install-autocomplete works. I forget restart my shell.

But is it possbile that enable bash completion by default with snap?

lengau commented 1 day ago

+1 on this.

Doing quick examination, terraform -install-autocomplete simply adds the following line to your bashrc:

complete -C /snap/terraform/711/terraform terraform

(Or I guess equivalent for the particular revision.)

A completion file that simply contains complete -C /snap/bin/terraform terraform and a completer key in the app entry should be sufficient.

jnsgruk commented 12 hours ago

Hmm, gave that a go locally, but no dice.

diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index c86522d..398fb3a 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -30,6 +30,7 @@ icon: snap/gui/terraform.png
 apps:
   terraform:
     command: terraform
+    completer: terraform-completer

 platforms:
   amd64:
@@ -56,5 +57,9 @@ parts:
       go mod download
       go build -ldflags "${LDFLAGS}"
       cp terraform $SNAPCRAFT_PART_INSTALL/terraform
+
+      echo -e '#!/usr/bin/env bash\ncomplete -C terraform terraform' > $CRAFT_PART_INSTALL/terraform-completer
+      chmod +x $CRAFT_PART_INSTALL/terraform-completer
     stage:
       - terraform
+      - terraform-completer

Will try a bit later if I get time, but feel free to have a play!