martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
8.39k stars 288 forks source link

cannot source autocompletions in zsh #67

Closed mayel closed 2 years ago

mayel commented 2 years ago

Expected Behavior

Auto-completions are sourced into the shell.

Actual Behavior

And error message appears and auto-completions are not sourced.

Steps to Reproduce the Problem

Here are different attempts and their results:

~ > source <(jj debug completion --zsh)

_arguments:comparguments:325: can only be called from completion function

~ > source (jj debug completion --zsh)

zsh: unknown file attribute: j

~ > source $(jj debug completion --zsh)

source: no such file or directory: #compdef

~ > source jj debug completion --zsh

/Users/me/.cargo/bin/jj:2: parse error near `)'

~ > jj debug completion --zsh | source

source: not enough arguments

Specifications

martinvonz commented 2 years ago

Jujutsu gets its completion script from Clap. See if clap-rs/clap#2488 has some useful information about sourcing the zsh script. There were a few steps mentioned there, which involved removing the last line of the script. Maybe those steps are what's needed? I'm not at a computer so I can't test it myself.

mayel commented 2 years ago

Thanks!

First tried using $fpath by putting fpath="jj debug completion --zsh":$fpath in ~/.zshrc and then when I typed jj and [tab] I got -zsh:1: _main_complete: function definition file not found

I then put this instead, with which autocompletions are working:

autoload -U compinit
compinit
source <(jj debug completion --zsh | sed '$d') # can also be `head -n -1` or whatever as long as the last line is removed
compdef _jj jj