Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Completions don't work with ntl alias on zsh #6940

Open
benhancock opened this issue Dec 1, 2024 · 2 comments · May be fixed by #6946
Open

Completions don't work with ntl alias on zsh #6940

benhancock opened this issue Dec 1, 2024 · 2 comments · May be fixed by #6946
Labels
type: bug code to address defects in shipped code

Comments

@benhancock
Copy link
Contributor

Describe the bug

Completions work with the netlify command, but not with the ntl alias. Trying to use tab with ntl does not produce any completions.

Thanks to @alexschcom for pointing this issue out

Steps to reproduce

  1. Install completions with completion:install for zsh
  2. Type netlify bl and press tab. This should autocomplete to netlify blobs
  3. Type ntl bl and press tab. This does not autocomplete

Configuration

No response

Environment

System:
OS: macOS 15.0
CPU: (8) arm64 Apple M2
Memory: 91.16 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.6.2 - ~/.nvm/versions/node/v21.6.2/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v21.6.2/bin/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v21.6.2/bin/npm
pnpm: 9.12.0 - ~/.nvm/versions/node/v21.6.2/bin/pnpm
npmGlobalPackages:
netlify-cli: 17.37.2

@benhancock benhancock added the type: bug code to address defects in shipped code label Dec 1, 2024
@benhancock
Copy link
Contributor Author

benhancock commented Dec 4, 2024

It appears that the reason for this is that shell completions are command-specific and do not automatically propagate to aliases without explicit configuration in either the completion script or the shell configuration.

Either of these fix the issue in zsh:

  1. Add ntl to the completion script itself (/Users/$user/.config/tabtab/netlify.zsh)
###-begin-netlify-completion-###
if type compdef &>/dev/null; then
  _netlify_completion () {
    local reply
    local si=$IFS

    IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" /Users/ben/.nvm/versions/node/v21.6.2/lib/node_modules/netlify-cli/dist/lib/completion/script.js completion -- "${words[@]}"))
    IFS=$si

    _describe 'values' reply
  }
  compdef _netlify_completion netlify ntl # Add `ntl` here <----------------
fi
###-end-netlify-completion-###
  1. Add compdef ntl=netlify to the user's shell config file:
# rest of zsh/bash/fish config ...

compdef ntl=netlify

@benhancock
Copy link
Contributor Author

benhancock commented Dec 4, 2024

It doesn't look like tabtab, the package the CLI uses for its completions, supports adding aliases for a completion script automatically.

However, we can write the completion script to add the ntl alias manually within src/commands/completion/completion.ts

This logic would work for zsh:

  // ... completion script installation

  const completionScriptPath = join(homedir(), `.config/tabtab/${parent.name()}.zsh`)

  if (fs.existsSync(completionScriptPath)) {
    let completionScript = fs.readFileSync(completionScriptPath, 'utf8')

    completionScript = completionScript.replace(
      /compdef _netlify_completion netlify/,
      'compdef _netlify_completion netlify ntl',
    )

    fs.writeFileSync(completionScriptPath, completionScript, 'utf8')
    log(`Added alias 'ntl' to completion script.`)
   
  }

 // ... rest of file

One problem with this approach is that it would require separate logic for zsh, bash, and fish, since they each have different mechanisms for defining completions

@benhancock benhancock changed the title Completions don't work with ntl alias Completions don't work with ntl alias on zsh Dec 5, 2024
@benhancock benhancock linked a pull request Dec 5, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant