oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.07k stars 2.76k forks source link

bun completion: do not overide my dotfiles #1272

Open undg opened 2 years ago

undg commented 2 years ago

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.

Jarred-Sumner commented 2 years ago

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

# bun: don't auto-source completions

undg commented 2 years ago

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

undg commented 2 years ago

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.

jason0x43 commented 1 year ago

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.

iloveitaly commented 1 year ago

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/
pesterhazy commented 1 year ago

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

marlonrichert commented 1 year ago

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.

iloveitaly commented 8 months ago

Here's a zsh plugin that is working for me

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