Hi! This is like a mini fresh produce; it’s more of a UX improvement than a platform feature
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.
Hi, is there any chance that the completion script is out of date or broken? I recently installed fly and generated the completions, but the options it is providing don’t seem valid.
Here’s how my zsh is set up and the versions of zsh and fly that I have installed
# I'm on macOS 14.4.1 (23E224)
$ zsh --version
zsh 5.9 (aarch64-apple-darwin23.4.0)
$ which fly
/opt/homebrew/bin/fly
$ fly version
fly v0.2.60 darwin/arm64 Commit: b380369efd87c52806b6ea132380886eb5a1f3d8 BuildDate: 2024-05-27T09:51:50Z
$ echo $fpath | sed 's/ /\n/g'
/opt/homebrew/share/zsh-completions
/Users/pd/.config/zsh/site-functions
# ...
I set up the completions like this:
$ fly completions zsh > ~/.config/zsh/site-functions/_fly
# open a new shell
$ rm -f ~/.zcompdump; compinit
Here’s what happens when I open a new terminal and type fly and then hit tab:
These commands don’t seem like they’re coming from fly at all, and they don’t work. I’m not sure what program they could be coming from. I checked, and there is no _fly in /opt/homebrew/share/zsh-completions that would be clashing with the generated ~/.config/zsh/site-functions/_fly.
One interesting thing is that, in this same terminal, sourcing the output of fly completion zsh with source <(fly completion zsh) directly works correctly and makes tab completion show the right options:
@peterldowns You installed the CLI utility for Concourse CI (which is also coincidentally named fly) alongside Fly.io’s flyctl. The first output (the one that mentions pipelines etc) is from Concourse’s fly, while the second (mentions e.g. consul and deploy) is from flyctl.
I also recommend uninstalling your existing fly, if you don’t have/use Concourse CI. Otherwise you need to figure out how/why both flys are conflicting and figure out a way to resolve the local conflict. For example, use Fly’s utility as flyctl and not fly.
@roadmr I have not installed the CLI utility for Concourse CI, but your comment helped me figure out what was going wrong.
Earlier I wrote that I had checked my fpath and didn’t see any other _fly completions that would be conflicting with the ones generated by fly completion zsh > ~/.config/zsh/site-functions/_fly:
I’m not sure what program they could be coming from. I checked, and there is no _fly in /opt/homebrew/share/zsh-completions that would be clashing with the generated ~/.config/zsh/site-functions/_fly.
The issue is that the zsh-completions package includes a _concourse file, which registers itself as a completion handler for the fly binary. So although it wasn’t named _fly, it did take precedence.
Thank you for your answer, as it helped me figure this out! I was able to solve my problem by simply re-ordering my fpath so that my personal completions in ~/.config/zsh/site-functions take precedence over those installed by the zsh-completions project: