zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
20.55k stars 637 forks source link

Cannot use `zr` or `zrf` without autocompleting `zellij` command once #1933

Open mnpqraven opened 1 year ago

mnpqraven commented 1 year ago

Basic information

zellij --version: 0.32.0 stty size: 34 72 uname -av: 6.0.6-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Oct 29 14:21:50 UTC 2022 x86_64 GNU/Linux alacritty --version: alacritty 0.11.0 omz version: master (fb66b67) Minimal .zshrc:

export ZSH="$HOME/.oh-my-zsh"
source $ZSH/oh-my-zsh.sh

Further information

citypaul commented 1 year ago

I'm currently seeing the same behaviour. I also tried source from my .zshrc file directly, and while this does work it produces this error every time I open a new shell:

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

I believe adding the completions file inside $fpath is the correct way, but as mentioned here this results in autocomplete not working unless a command has been ran at least once.

dubst3pp4 commented 1 year ago

I have the same issue as @citypaul. I've dumped the Zellij zsh completion into a separate file and sourced it in my .zshrc.

pitoniak32 commented 1 year ago

I also have the same issue. I was able to find a workaround that got me the functionality I was looking for originally, it does not address the bug here but it will get rid of the warning if you are just looking to use the functions.

I just deleted everything in the completions and left the functions.

#compdef zellij

function zr () { zellij run --name "$*" -- zsh -ic "$*";}
function zrf () { zellij run --name "$*" --floating -- zsh -ic "$*";}
function ze () { zellij edit "$*";}
function zef () { zellij edit --floating "$*";}
kseistrup commented 1 year ago

This is also an issue in fish.


The fish shell has user completions in …/completions/ and user defined functions/aliases in …/functions/, where is the fish configuration directory.

If completions are saved as zellij.fish and the functions in separate files (zr.fish and so on), everything will be loaded automatically.

In the current (v0.35.2) setup functions aren't loaded until after first attempt of completion.

See also: #2186

Edit: Added reference to issue 2186.

slashformotion commented 1 year ago

I did the same as @dubst3pp4 and for some reason i get _arguments:comparguments:327: can only be called from completion function

bomgar commented 1 year ago

Same issue here. I have this workaround in my zshrc

if [[ -x "$(command -v zellij)" ]];
then
    eval "$(zellij setup --generate-completion zsh | grep "^function")"
fi;
siuyutpang commented 10 months ago

same issue occurs in 0.38.2 version, I think it make no sense that put alias function in the completion file, they should be seperated into different files

siuyutpang commented 10 months ago

Same issue here. I have this workaround in my zshrc

if [[ -x "$(command -v zellij)" ]];
then
    eval "$(zellij setup --generate-completion zsh | grep "^function")"
fi;

😂 a bit strange solution, but it really works

Deebster commented 6 months ago

I found this with bash on a Fedora 39 server.

My hack fix was to move the functions into ~/.bashrc.d/zellij.bash

silicakes commented 6 months ago

Just ran into this, macos + zsh here

s4Dt0y commented 4 months ago

I also ran into this...if so many people are experiencing this, since 2022, shouldn't the docs be editted? Is there some reason no PR is being opened?

cristiand391 commented 4 months ago

I also ran into this...if so many people are experiencing this, since 2022, shouldn't the docs be editted? Is there some reason no PR is being opened?

IIRC, we talked about updating docs for this in Discord but since these have to be maintained (keep up-to-date, etc) it was decided to leave them they are until a fix for this is found.

I explored this but couldn't find a fix that didn't require splitting completion functions from normal ones: https://github.com/zellij-org/zellij/discussions/1860#discussioncomment-7979069

Lockszmith-GH commented 1 month ago

I finally got zellij zsh completion to work using the zsh definition using the following workarounds:

# 1 Using zsh's native compinit:

Apparently the 2022 update of ZSH (currently the latest) had some changes to discourage loading of completion code manully, and favours auto loading when it's needed. However some users (and app maintainers) have founds how to workaround it. The solution is to manually call compdef _<command_name> <command_name> after the definition to load it manually.

The sed below takes care of that.

autoload -U +X compinit && compinit
. <( zellij setup --generate-completion zsh | sed -Ee 's/^(_(zellij) ).*/compdef \1\2/' )

# 2 Using bashcompinit bash-completion wrapper:

autoload -U +X compinit bashcompinit && compinit && bashcompinit
. <( zellij setup --generate-completion bash )

I personally prefer # 1, but in case that stops to work # 2 can be a fallback until things are fixed again.

@imsnif could you update the --generate-completion zsh to replace the _zellij call with compdef _zellij zellij ?