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

nom-build: zsh bridge does not work #2375

Open
2 of 11 tasks
Atemu opened this issue May 6, 2024 · 22 comments
Open
2 of 11 tasks

nom-build: zsh bridge does not work #2375

Atemu opened this issue May 6, 2024 · 22 comments
Labels
bug Something isn't working linux nushell zsh

Comments

@Atemu
Copy link

Atemu commented May 6, 2024

Current Behavior

Attempting to complete nom-build which ships a zsh-completion in CARAPACE_BRIDGES=zsh nu does not work: NO RECORDS FOUND.

Perhaps this is to do with the completion being equal to some other completion?

Expected Behavior

It should do zsh nix-build completions for nom-build.

Steps To Reproduce

  1. In an env where zsh and nix-output-monitor are installed
  2. Run CARAPACE_BRIDGES=zsh nu
  3. Try to complete nom-build <TAB>

Version

1.0.2

OS

  • Linux
  • OSX
  • Windows

Shell

  • Bash
  • Elvish
  • Fish
  • Nushell
  • Oil
  • Powershell
  • Xonsh
  • Zsh

Anything else?

Nom basically declares itself as an alias. That may be the reason?

Related to this: Should carapace attempt to use its own completions for the command aliased by the bridge or should it use the bridge's aliased command via the bridge too?

Least surprise would probably be to use the aliased command completion via the bridge as command aliases should be handled by carapace itself for native completions.

@Atemu Atemu added the bug Something isn't working label May 6, 2024
@rsteube
Copy link
Member

rsteube commented May 6, 2024

Nom basically declares itself as an alias. That may be the reason?

Yeah possibly. Haven't gone too deeply into that edge case.

Apart from that carapace uses a custom config at ~/.config/carapace/bridge/zsh/.zshrc, so if the nom-build completion is registerd in ~/.zshrc that needs to be repeated there.

There's a custom completer for nix-build in carapace. Might be easier to just bridge completions for that one with a spec:

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: nom-build
parsing: disabled
completion:
  positionalany: ["$carapace.bridge.CarapaceBin([nix-build])"]

@Atemu
Copy link
Author

Atemu commented May 6, 2024

Oh so that's what the carapace bridge is for; it struck me as kind of odd.

@rsteube
Copy link
Member

rsteube commented May 6, 2024

Sourcing the users .zshrc can be very slow (depending on whate users put in there) and have some nasty side effects.
So I'm kinda forced to use a seperate one.
System wide registered completions should work though.

@Atemu
Copy link
Author

Atemu commented May 7, 2024

Ah, sorry I forgot to reply to that part; this is indeed a system-wide completion. It's not at the usual path as I'm on NixOS but the default system zsh is made to discover it just fine.

@blindFS
Copy link

blindFS commented Dec 6, 2024

@rsteube For me, CARAPACE_BRIDGES=zsh doesn't work at all, however anything defined in ~/.config/carapace/bridges.yaml is working perfectly. I wonder how to make zsh the default bridge for all commands that lack a default completer?

my ~/.config/carapace/bridge/zsh/.zshrc:

fpath=(/run/current-system/sw/share/zsh/site-functions $fpath)
autoload -U compinit && compinit

@blindFS
Copy link

blindFS commented Dec 6, 2024

CARAPACE_BRIDGES do make differences:

image

but the completion just not working for nushell.

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

The amount shown in --list does not use your fpath in ~/.config/carapace/bridge/zsh/.zshrc.
See https://github.com/carapace-sh/carapace-bridge/blob/master/pkg/bridges/zsh.go#L23

Is this just related to a specific completer, or a general issue with the zsh bridge?
Might just need to ensure ~/.config/carapace/bridge/zsh/.zshrc is used so that completion functions from the updated fpath are registered.

@blindFS
Copy link

blindFS commented Dec 6, 2024

@rsteube All commands specified in ~/.config/carapace/bridges.yaml works as expected, so I think fpath is loaded correctly.
The only issue for me is that, the list of commands that I want to bridge to zsh can be long, and I really want the CARAPACE_BRIDGES env var to work in a sense that all commands missing the completion info fallback to the zsh bridge, or maybe it's designed work in other ways?

Just curious about how to specify a default bridge without manually adding stuffs to bridges.yaml.

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

CARAPACE_BRIDGES does exactly that.
If none is registered in carapace it falls back to the bridged completion.

@blindFS
Copy link

blindFS commented Dec 6, 2024

The behavior of an empty bridges.yaml:

image

while with atuin: zsh in it:

image

and with a non-empty bridges.yaml that doesn't contain atuin:

image

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

Woah, the first one is nasty - gotta fix that.

Does the second still work if you comment out fpath=(/run/current-system/sw/share/zsh/site-functions $fpath)?

@blindFS
Copy link

blindFS commented Dec 6, 2024

@rsteube no, the completion file _atuin lies in the directory.

image

PS. If I remove bridges.yaml the behavior is the same as the 3rd situation above.

My carapace version is 1.0.7, I'd like to provide any information that you think might be helpful to debug the issue.

@blindFS
Copy link

blindFS commented Dec 6, 2024

Does fpath stops CARAPACE_BRIDGES to work?

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

That pretty much confirms what i meant above.
Customizing fpath is fine, the problem is that the list of available completions is generated with

zsh --no-rcs -c 'printf "%s\n" $fpath'

So the path containing the atuin completion is missing.
During actual completion however the custom .zshrc is sourced, which is why it works with bridges.yaml.
CARAPACE_BRIDGES simply doesn't know that the completion exists.

I just need to source the .zshrc for this to work.

Another (unreated) caveat: this currently only works for fpath based completions and not directly sourced ones (source <(cmd completion)).
But that would be a bad idea anyway in regards to performance (i should add some documentation for this).

@blindFS
Copy link

blindFS commented Dec 6, 2024

@rsteube I see, so you're going to make CARAPACE_BRIDGES also load the custom ~/.config/carapace/bridge/zsh/.zshrc, then everything should work as I expected.

For now, bridges.yaml should be the only option for me, am I following correctly?

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

Pretty much, unless you extend your fpath system wide. AFAIK the --no-rcs option only skips your user .zshrc.

@rsteube
Copy link
Member

rsteube commented Dec 6, 2024

@blindFS Should be working now in master if you want to give it a try.
Nightly build will also trigger in a couple hours.

@Atemu was this maybe your issue as well?

@Atemu
Copy link
Author

Atemu commented Dec 6, 2024

I'll check but I'll have to rebuild this setup again.

@blindFS
Copy link

blindFS commented Dec 7, 2024

CARAPACE_BRIDGES still doesn't work with the latest nightly build

image

The panic is fixed though.

And carapace --list --all | wc still not increased.

@rsteube
Copy link
Member

rsteube commented Dec 7, 2024

Ah sorry, I forgot to write the important bit:

carapace --clear-cache
source <(carapace _carapace)

The list of available completers is cached at ~/.cache/carapace/bridges-zsh.json.
So whenever you change/install something it needs to be cleared.

If it still doesn't work please share your _atuin completion file, I'll try it locally.

@blindFS
Copy link

blindFS commented Dec 7, 2024

@rsteube Works perfectly, thanks for the quick fix!

@haennes
Copy link

haennes commented Dec 14, 2024

For anyone stumbling upon this.
This is my carapace config in nix home-manager that works as of now:

{ pkgs, ... }: {
  programs.zsh.envExtra = ''
    export CARAPACE_BRIDGES="zsh"
    export CARAPACE_EXCLUDES="nix"
  '';

  programs.carapace = {
    enable = true;
    enableZshIntegration = true;
  };

  xdg.configFile = let
    onChange = ''
      ${pkgs.carapace}/bin/carapace --clear-cache
    '';
  in {
    "carapace/bridges.yaml" = {
      inherit onChange;
      text = ''
        # yaml-language-server: $schema=https://carapace.sh/schemas/command.json
        name:  nix
        description: nix build tool
        parsing: disabled
        completion:
          positionalany: ["$carapace.bridge.Zsh([nix])"]
      '';
    };
  };
}

a more up to date version might be available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linux nushell zsh
Projects
None yet
Development

No branches or pull requests

4 participants