Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Completions don't work #6724

Closed
alexschcom opened this issue Jun 23, 2024 · 7 comments · Fixed by #6882
Closed

Completions don't work #6724

alexschcom opened this issue Jun 23, 2024 · 7 comments · Fixed by #6882
Labels
type: bug code to address defects in shipped code

Comments

@alexschcom
Copy link

alexschcom commented Jun 23, 2024

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

  1. run netlify completion:install
  2. type netlify s
  3. 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

@benhancock
Copy link
Contributor

@dylanspyer and I had this issue too on zsh. There are at least two issues that might cause completion to fail

  1. 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
  1. 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; compinit to the user’s ~/.zshrc file above the Tabtab config line to load and then run compinit

This PR attempts to address both of these issues by:

  1. automatically outputting the chmod +x command with the appropriate file path for the user to copy and run if needed after the installation is complete;
  2. prompting the user to have the autoload -U compinit; compinit line added to the top of their ~/.zshrc file automatically if not already present.

@alexschcom
Copy link
Author

alexschcom commented Nov 30, 2024

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.

@benhancock
Copy link
Contributor

benhancock commented Nov 30, 2024

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?

@alexschcom
Copy link
Author

alexschcom commented Dec 1, 2024

@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

@benhancock
Copy link
Contributor

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
    Screen Recording 2024-12-01 at 10 53 00 AM
  • 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:

  1. Does simply moving the tabtab completion line to the bottom of the file change anything?
  2. Does resetting your OMZ completion cache change anything?

@alexschcom
Copy link
Author

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.

@benhancock
Copy link
Contributor

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
2 participants