Completions don't work
Describe the bug
I ran netlify completion:install, with the following output:
? Which Shell do you use ? zsh
? We will install completion to ~/.zshrc, is it ok ? Yes
=> Tabtab line already exists in ~/.config/tabtab/__tabtab.zsh file
=> Tabtab line already exists in ~/.zshrc file
=> Wrote completion script to /Users/alex/.config/tabtab/netlify.zsh file
=> Tabtab source line added to ~/.zshrc for netlify package.
Make sure to reload your SHELL.
Completion for netlify successful installed!
But no completions when tabbing :(
Steps to reproduce
- run
netlify completion:install - type
netlify s - press tab
Completions for serve, sites, status, switch should appear
Configuration
No response
Environment
System: OS: macOS 14.5 CPU: (8) arm64 Apple M1 Memory: 63.78 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.3.0 - /opt/homebrew/bin/node npm: 10.8.1 - /opt/homebrew/bin/npm pnpm: 8.15.6 - /opt/homebrew/bin/pnpm npmGlobalPackages: netlify-cli: 17.29.0
@dylanspyer and I had this issue too on zsh. There are at least two issues that might cause completion to fail
- On Linux/MacOS, the completion script may not have the necessary executable permissions.
- Fix: Run chmod +x with the file path to the completion script, typically
/Users/yourname/projects/netlify/netlify-cli/dist/lib/completion/script.js
- Netlify uses Tabtab for completions, and with zsh, Tabtab (and other) completions do not work until compinit has been run.
- Fix: Add the line
autoload -U compinit; compinitto the user’s~/.zshrcfile above the Tabtab config line to load and then runcompinit
This PR attempts to address both of these issues by:
- automatically outputting the
chmod +xcommand with the appropriate file path for the user to copy and run if needed after the installation is complete; - prompting the user to have the
autoload -U compinit; compinitline added to the top of their~/.zshrcfile automatically if not already present.
Hey @benhancock — So I just made sure everything's set up according to what you said, but unfortunately completions still don't appear. The only thing I noticed was that the completion script for me was located at /opt/homebrew/lib/node_modules/netlify-cli/dist/lib/completion/script.js, which is correctly referenced in ~/.config/tabtab/netlify.zsh, though.
Hey @alexschcom, is this even after running source ~/.zshrc / restarting your terminal?
If so, when you view the contents of ~/.zshrc, do you see a line at the very top that reads "autoload -U compinit; compinit"? Note that this line must appear above the tabtab completion line, which is usually towards the bottom.
If the compinit line is at the top and completions still aren't working, would you care to post the contents of your ~/.zshrc file?
@benhancock Yes to both. Here's my ~/.zshrc
HISTSIZE=1000
SAVEHIST=10000
PATH="$PATH:/Users/alex/Code/shell_scripts"
PATH="$PATH:/Users/alex/woff2/out"
export PATH=$PATH
# autojump
[[ -s /Users/alex/.autojump/etc/profile.d/autojump.sh ]] && source /Users/alex/.autojump/etc/profile.d/autojump.sh
autoload -U compinit; compinit
# tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/__tabtab.zsh ]] && . ~/.config/tabtab/__tabtab.zsh || true
# iTerm2 shell integration
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Set up fzf key bindings and fuzzy completion
source <(fzf --zsh)
# Oh My Zsh
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
DISABLE_AUTO_TITLE="true"
ENABLE_CORRECTION="true"
plugins=(git zsh-syntax-highlighting zsh-autosuggestions aliases)
source $ZSH/oh-my-zsh.sh
Note I have tried moving the autoload -U compinit; compinit to the very first line, reloaded my terminal, but to no avail
Hey @alexschcom, I installed Oh My Zsh with your plugins and theme and using the same ~/.zshrc contents (with my name and paths swapped in for yours), and installed the netlify-cli via homebrew to match your installation. I’m not able to replicate the issue exactly. I suspect one of the Oh My Zsh (OMZ) plugins might be interfering with tabtab completions, but I’m not certain. Here’s what I’ve observed:
- When I comment out the plugins line in my
~/.zshrc(plugins=(git zsh-syntax-highlighting zsh-autosuggestions aliases)), completions only work if the tabtab initialization line is placed below the OMZ-related lines. See gif - However, if the plugins line is not commented out, completions work regardless of whether the tabtab line is near the top or at the bottom of the file. So, it's not clear if the problem you're seeing has to do with the OMZ plugins or not.
A couple suggestions:
- Does simply moving the tabtab completion line to the bottom of the file change anything?
- Does resetting your OMZ completion cache change anything?
Hey @benhancock, first of all, thanks a lot for your effort! I reset the OMZ completion cache and completions now work with the netlify command (I used to test with the ntl alias, where it still doesn't). FYI I installed the cli with npm, not homebrew — not sure if that matters.
Good to hear! I'm also seeing that completions don't work with the ntl alias -- I'll go ahead and open a new issue for that.
I'm not sure about npm vs homebrew, but I wonder why npm put your netlify-cli installation in /opt/homebrew/lib/node_modules/netlify-cli and not something like /Users/ben/.nvm/versions/node/v21.6.2/lib/node_modules/netlify-cli (where it put mine). Glad resetting the completion cache did the trick