oven-sh / bun

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

Bash autocomplete #6037

Open manast opened 11 months ago

manast commented 11 months ago

What is the problem this feature would solve?

Since Bun's early days, I have been annoyed by this missing feature: bash autocomplete does not work! https://sourabhbajaj.com/mac-setup/BashCompletion/ On all Unix commands, I expect bash autocompletion to work, this is specially annoying if you want to use bun to execute a script that is inside a nested directory. Not sure why it is not working on bun, I thought this was a feature of bash that all commands got for free, maybe something in bun is preventing this default behaviour?

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

Fix bun so that autocompletion works.

What alternatives have you considered?

None.

Nekosis commented 11 months ago

I thought this was a feature of bash that all commands got for free, maybe something in bun is preventing this default behaviour?

No. Bash completions need to be written manually, so Bun will need to create their own.

manast commented 11 months ago

Ah ok. I think bun does actually have its own, and that's why it is not working as expected. For example, if I type bun and press TAB, I get something like:

-- scripts --
dev                                              start
-- command --
add      -- Add a dependency to package.json
bun      -- Generate a bundle
create   -- Create a new project
dev      -- Start a dev server
help     -- Show command help
install  -- Install packages from package.json
pm       -- Manage local packages
remove   -- Remove a dependency from package.json
run      -- Run a script or package bin
upgrade  -- Upgrade to the latest version of bun
x        -- Run a command from a local or remote NPM package
-- files --

But if I type bun sr and the press TAB it does not autocomplete to the src directory, whereas if I just type any other unix command or even an unexisting command, it will autocomplete the directory and let me navigate in the files by tabbing.

Nekosis commented 11 months ago

I don't think you're supposed to call bun example.js to directly run a file. Don't you mean bun run example.js?

manast commented 11 months ago

Aha. Using "bun run" the autocomplete actually works. But you can use bun without run and it works the same (besides autocomplete), for example:

bun --watch src/index.ts
Nekosis commented 11 months ago

I see. I've never used a program that could put keywords/commands and file paths in the same field before, so I wouldn't know if this is a Bun problem or a bash-completion problem.

For reference, Bash completions are just shell scripts. If you're at all familiar with Bash scripting, maybe you'd want to take a look at Bun's completions script to see if you can narrow down the issue.

jkomyno commented 4 months ago

Autocompletion works with bun run ..., not with bun ... (bun@1.1.6).

manast commented 4 months ago

bun's bash autocomplete works badly actually, like it behaves completely differently than any other Unix command... I am surprised nobody seems to care 🤷‍♂️