cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.65k stars 102 forks source link

Better shell completions #778

Closed bartekpacia closed 2 months ago

bartekpacia commented 3 months ago

Assumptions:

$ tart list
Source Name                                                                                                          Disk Size State
local  example-sonoma-2                                                                                                90   58   stopped
local  example-sonoma-1                                                                                               90   58   stopped
oci    ghcr.io/cirruslabs/macos-sonoma-xcode:15.3                                                                    90   59   stopped
oci    ghcr.io/cirruslabs/macos-sonoma-xcode:latest                                                                  90   59   stopped
oci    ghcr.io/cirruslabs/macos-sonoma-xcode@sha256:03e19261894c588f9d478a7cd948992a025c66518189abeb9df501bcdd5ea568 90   59   stopped

Current behavior

When completion is triggered, nothing is printed.

$ tart run [tab]

Expected behavior

Available VMs (the local ones) are suggested:

$ tart run [tab]
example-sonoma-1    example-sonoma-2

Implementation

Tart's CLI uses Swift ArgumentParser, and looks like it has support for accurate, customized shell completions and supports the use case I described above.

I'm happy to submit a PR for this when I find some free time, if you agree with this feature suggestion.

todd-dsm commented 1 month ago

Here's what I ended up with...

Installed via homebrew on my work laptop. These installs always drop completions in the same directory:

% brew install tart
==> Fetching cirruslabs/cli/tart
==> Downloading https://github.com/cirruslabs/tart/releases/download/2.10.0/tart-arm64.tar.gz
Already downloaded: /Users/thomas/Library/Caches/Homebrew/downloads/5407e492e27b73c6de2bc751f5233f1d57ff9e4c2c96677e843398931b7b1a47--tart-arm64.tar.gz
==> Reinstalling cirruslabs/cli/tart 
==> Caveats
See the GitHub repository for more information

zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions  <-- completions are here
==> Summary
🍺  /opt/homebrew/Cellar/tart/2.10.0: 12 files, 11.6MB, built in 2 seconds
==> Running `brew cleanup tart`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

I use OMZSH; given the location of the completions, omzsh should just pick it up and run with it.


That said, my work laptop totally fires off completions - just realized my personal laptop does not 😂 that alone implies an environmental (configuration) issue.

I'll test some more and post if anything reveals itself.

todd-dsm commented 1 month ago

I found a quick fix that allows me to get past this but:

% cat ~/.zprofile
# Homebrew Stuff
eval "$(/opt/homebrew/bin/brew shellenv)"
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"

The first line is necessary; the second like only exists because of a failure somewhere upstream. The failure should be identified and solved.

But this works in a pinch.

bartekpacia commented 1 month ago

@todd-dsm I have this in my ~/.zshrc. It's standard setup as recommended by Homebrew (link).