Last active
January 31, 2025 01:48
-
-
Save calvinf/05685d1bbbd0dc3235936a8259d0fde3 to your computer and use it in GitHub Desktop.
Bun autocomplete for bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
_bun_complete() { | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
# Define the main commands | |
local commands="add build create exec init install link outdated patch pm publish remove repl run test unlink update upgrade x" | |
# Define some common flags | |
local flags="--watch --hot --no-clear-screen --smol -r --preload --inspect --inspect-wait --inspect-brk --if-present --no-install --install -i -e --eval -p --print --prefer-offline --prefer-latest --port --conditions --fetch-preconnect --max-http-header-size --dns-result-order --expose-gc --no-deprecation --throw-deprecation --title --silent --elide-lines -v --version --revision -F --filter -b --bun --shell --env-file --cwd -c --config -h --help" | |
local scripts=$(bun getcompletes s) | |
case "${prev}" in | |
bun) | |
COMPREPLY=( $(compgen -W "${commands} ${scripts}" -- ${cur}) ) | |
return 0 | |
;; | |
run) | |
COMPREPLY=( $(compgen -W "${scripts}" -- ${cur}) ) | |
return 0 | |
;; | |
*) | |
# For other commands, suggest flags or nothing | |
COMPREPLY=( $(compgen -W "${flags}" -- ${cur}) ) | |
return 0 | |
;; | |
esac | |
} | |
complete -F _bun_complete bun |
The Fish completions file is a good place to learn more: https://github.com/oven-sh/bun/blob/c8f8d2c0bbc80a747ec0235b390866d043dc1d9f/completions/bun.fish
Thanks, @mangs!
You're very welcome. I've been down this rabbit hole before. 😀
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! FYI you can get the current list of
script
entries frompackage.json
by runningbun getcompletes s