Quality-of-life: shell completion for Flyctl

Hi! This is like a mini fresh produce; it’s more of a UX improvement than a platform feature :slight_smile:

Flyctl now supports shell completion for apps, orgs, and regions!

That means you can type fly apps restart ⇥ and get autocompletion for the apps you have access to. If you have multiple apps, this is so convenient. I’ve missed it so bad every time I’ve had to use the release version of flyctl instead of the feature branch!

If you haven’t enabled shell completions yet (we don’t advertise it enough!), this would be a great time to try it out! Here’s instructions to enable completions for the four shells supported by Cobra, the CLI library we use:

Bash

Completion for bash depends on the bash-completion package.

  $ source <(flyctl completion bash)

  # To load completions for each session, execute once:
  # Linux:
  $ flyctl completion bash > /etc/bash_completion.d/flyctl
  # macOS:
  $ flyctl completion bash > $(brew --prefix)/etc/bash_completion.d/flyctl

  # To enable completion for fly, rather than just flyctl
  $ echo 'alias fly=flyctl' >> ~/.bashrc
Zsh
  # If shell completion is not already enabled in your environment,
  # you will need to enable it.  You can execute the following once:

  $ echo "autoload -U compinit; compinit" >> ~/.zshrc

  # To load completions for each session, execute once:
  $ flyctl completion zsh > "${fpath[1]}/_flyctl"
  # To enable completion for fly, rather than just flyctl
  $ echo 'compdef _flyctl fly' >> ~/.zshrc

  # You will need to start a new shell for this setup to take effect.
Fish
  $ flyctl completion fish | source

  # To load completions for each session, execute once:
  $ flyctl completion fish > ~/.config/fish/completions/flyctl.fish
  # To enable completion for fly, rather than just flyctl
  $ echo 'alias fly=flyctl' >> ~/.config/fish/config.fish
Powershell
  PS> flyctl completion powershell | Out-String | Invoke-Expression

  # To load completions for every new session, run:
  PS> flyctl completion powershell > flyctl.ps1
  # and source this file from your PowerShell profile.

(These instructions are adapted from the Cobra documentation)

Encounter any flags or commands you wish had shell completions? Trouble getting this working with your shell? Post it here and we’ll take a look!

Hope you all like this one as much as I do! :smile:

19 Likes