zellij-org / zellij

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

Fish function are not completions #2186

Open Zykino opened 1 year ago

Zykino commented 1 year ago

Doing zellij setup --generate-completion fish > ~/.config/fish/completions/zellij.fish create a lot of nice completions around zellij.

I have 2 issues with it: The completions files are evaluated lazily but some functions are in there ze zrf… They should be in ~/.config/fish/functions/zellij.fish where they will be evaluated more eagerly (so I can use ze without having to do zellij [Tab] first. => We need 2 generation commands or 2 outputs. This can be worked around and fixed manually… if the users know all that :sweat_smile:. I’m not sure how other shell’s completions are working.

zellij run [Tab] (and zellij action new-pane [Tab], maybe others too) try to complete with local folder instead of commands. I’m not sure it can be addressed, I do not know the fish completion ^^'.

Zykino commented 1 year ago

Note: As a user, to save the functions just do:

zellij setup --generate-completion fish > ~/.config/fish/completions/zellij.fish
zellij [Tab] [Ctrl+c]
funcsave zr
funcsave zrf
funcsave ze
funcsave zef

This will save each function into its own autoloaded function file in ~/.config/fish/functions/z*.

imsnif commented 1 year ago

Yeah, I'll readily admit I kind of hacked these together in the last minute before the release. So you're suggesting adding a --generate-shell-aliases flag instead? Or some other name?

Zykino commented 1 year ago

I don’t really know. Another possibility is to generate all files and directory structure (possibly in /tmp/zellijConfig). And in stdout tell the user to inspect it and then mv /tmp/zellijConfig ~/.config/fish if they are ok to keep it. I mean, if you do not want to overwrite default config automatically.

I’m not sure generating multiples aliases is possible in a single file, the way fish works. Or maybe ze and zef in ze.fish and the same for the zr family? I must admit, I use fish but am not well versed into its configs.

Zykino commented 1 year ago

skim does not propose auto-installing their function (or I’m not aware how). They propose this file: https://github.com/lotabout/skim/blob/master/shell/key-bindings.fish. I installed it with:

curl https://raw.githubusercontent.com/lotabout/skim/master/shell/key-bindings.fish > ~/.config/fish/functions/skim.fish
< edit the file to insert the command as a reminder ;) >

zellij can offer the same and all the aliases in the same file: zellij.fish.

Thinking again, maybe this can be a good citizen default: not "steal" all the short name and expose the quick functions as zellije, zellijef, zellijr, zellijrf. Easier to remember/learn for occasional user.

Maybe on the "shell integration" doc can propose to do the abbr -a -U -- ze zellije.

jirijakes commented 1 year ago

I don't know what would be the fishiest way but one more option how to make the completions and aliases work now is adding:

zellij setup --generate-completion fish | source

into config.fish. It's probably not the most idiomatic way but AFAIK it's also what zoxide and starship recommend.

Zykino commented 1 year ago

Effectively starship and skim ask to do something like this in the config.fish, inside the if status is-interactive block.

if status is-interactive
    # Commands to run in interactive sessions can go here

    # Skim key bindings
    source ~/.config/fish/functions/skim.fish
    skim_key_bindings

    starship init fish | source
end

So this is a possibility, but I prefer skim's setup: do not generate the config each time. Especially for the completion: as a user you prefer them not to change without your knowledge.

valankar commented 1 year ago

Yeah, I'll readily admit I kind of hacked these together in the last minute before the release. So you're suggesting adding a --generate-shell-aliases flag instead? Or some other name?

I thinking having a --generate-shell-aliases makes sense. https://fishshell.com/docs/current/completions.html#where-to-put-completions indicates there being a completions directory separate from the functions directory. I ended up putting the functions in ~/.config/fish/functions/zellij.fish and completions in ~/.config/fish/completions/zellij.fish.

Zykino commented 1 year ago

I saw #2650 is trying to fix this :)

aldanor commented 11 months ago

Another thing I noticed (unless it has been already discussed somewhere), in the fish shell,

I.e.,

Edit: it looks like those functions are missing --wraps="zellij edit" and --wraps="zellij edit --floating" in order for auto-complete to behave correctly. Edit 2: actually no, sometimes it fixes it, sometimes it doesn't. I'm not quite what makes it behave right or wrong.

upryst commented 3 months ago

Struggling with zef completion behaviour as well. It looks like there's a collision with zef from Raku universe, which Fish is trying to support out of the box.

Erasing the conflicting completion makes zef act like the other aliases:

$ complete -e zef