bun icon indicating copy to clipboard operation
bun copied to clipboard

bun completion: do not overide my dotfiles

Open undg opened this issue 2 years ago • 3 comments

What is the problem this feature will solve?

When I'm generating completions by bun, .zshrc is changed. It's my little .zshrc and strangers should not touch him. He can grow up on pervert or something.

I'm using separate folders for completions: generated, written manually and pulled from the zsh-completion community. I'm sourcing them in my way. I don't want bun to touch my dotfiles to source one completion.

What is the feature you are proposing to solve the problem?

  1. Add an extra flag that will prevent overriding personal files.
  2. Add an extra flag that will override fish config or .zshrc and don't touch it by default. (I prefer this one)

What alternatives have you considered?

IDK what I can do. Not updating bun? Not really a solution. chmoding zshrc? Bit overkill. As far as I know, completion is regenerated after an update. I'm installing it from AUR, not sure if that issue is present when updating it by YAY. I'll look at this closer after the next update.

undg avatar Sep 23 '22 12:09 undg

What if I make it look for this string in .zshrc and skip saving it if so?

# bun: don't auto-source completions

Jarred-Sumner avatar Sep 23 '22 13:09 Jarred-Sumner

Yes, that will be perfect. Whatever is sensible and doesn't involve much effort. Thank you.

undg avatar Oct 21 '22 08:10 undg

That comment flag can be auto added next to source(before, after 👐). It will require no documentation to figure out what's what by simply seeing it.

If I'm not wrong, you don't need to change the path every time an update is made. Unless I'm wrong and the path for the autocompletion file is not stable yet.

undg avatar Oct 27 '22 00:10 undg

What if I make it look for this string in .zshrc and skip saving it if so?

Other tools I use (deno, 1password-cli, rtx) that generate completions simply output them to stdout and don't modify any files. That's simpler for the tool, and it's easy for the user to put the completions in the proper place on the local system (such as a zsh/site-functions directory). It'd be a nice option.

jason0x43 avatar Mar 25 '23 13:03 jason0x43

Big +1 on this one. Would be great to have a zsh plugin that does something like:

bun completions # generate but don't mutate zshrc
fpath+=~/.bun/

iloveitaly avatar Aug 04 '23 13:08 iloveitaly

This bit me hard because it creates a conflict with zsh-autocomplete

With bun completions enabled:

~$ % arch(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command
(eval):1: command not found: _autocomplete.command

The probably disappears when I turn off

[ -s "/Users/user/.bun/_bun" ] && source "/Users/user/.bun/_bun"

Took a while to bisect this issue. Note that this was on an older version of bunjs (0.6.13) so the problem may have been fixed in the meantime.

However, it highlights the fact that zsh completions should be opt in because they're potentially risky

pesterhazy avatar Aug 13 '23 12:08 pesterhazy

These lines in bun.zsh are a definite no-no:

if ! command -v compinit >/dev/null; then
    autoload -U compinit && compinit
fi

compdef _bun bun

Please see this guide I wrote on how to properly install Zsh completions.

marlonrichert avatar Aug 16 '23 17:08 marlonrichert

Here's a zsh plugin that is working for me

https://gist.githubusercontent.com/iloveitaly/357a72f0f9e70f3a7d2aa6f8c40cf956/raw/795917afc433cd8897eba96fab3941791813a122/bun.plugin.zsh

iloveitaly avatar Feb 13 '24 14:02 iloveitaly