aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-23 00:59:41 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-23 00:59:41 -0800
commitf6a62c01bf6b50b9e19fec25fb80950eb76da4a4 (patch)
tree8db1d45be129f7d5de463e989b2bc9a2244f935d
parent979074de2bbaca8d6678cb4f8b61be3c1025a48e (diff)
downloadbun-f6a62c01bf6b50b9e19fec25fb80950eb76da4a4.tar.gz
bun-f6a62c01bf6b50b9e19fec25fb80950eb76da4a4.tar.zst
bun-f6a62c01bf6b50b9e19fec25fb80950eb76da4a4.zip
Cherry-pick #1638
Closes #1638
-rw-r--r--completions/bun.bash12
-rw-r--r--completions/bun.fish29
-rw-r--r--completions/bun.zsh80
-rw-r--r--src/cli.zig2
4 files changed, 109 insertions, 14 deletions
diff --git a/completions/bun.bash b/completions/bun.bash
index 9537cdb88..a42705789 100644
--- a/completions/bun.bash
+++ b/completions/bun.bash
@@ -1,6 +1,5 @@
#/usr/bin/env bash
-
_file_arguments() {
shopt -s extglob globstar
local extensions="${1}";
@@ -81,8 +80,9 @@ _subcommand_comp_reply() {
_bun_completions() {
declare -A GLOBAL_OPTIONS;
declare -A PACKAGE_OPTIONS;
+ declare -A PM_OPTIONS;
- local SUBCOMMANDS="dev bun create run install add remove upgrade completions discord help init";
+ local SUBCOMMANDS="dev bun create run install add remove upgrade completions discord help init pm x";
GLOBAL_OPTIONS[LONG_OPTIONS]="--use --cwd --bunfile --server-bunfile --config --disable-react-fast-refresh --disable-hmr --extension-order --jsx-factory --jsx-fragment --extension-order --jsx-factory --jsx-fragment --jsx-import-source --jsx-production --jsx-runtime --main-fields --no-summary --version --platform --public-dir --tsconfig-override --define --external --help --inject --loader --origin --port --dump-environment-variables --dump-limits --disable-bun-js";
GLOBAL_OPTIONS[SHORT_OPTIONS]="-c -v -d -e -h -i -l -u -p";
@@ -95,6 +95,9 @@ _bun_completions() {
PACKAGE_OPTIONS[SHARED_OPTIONS_LONG]="--config --yarn --production --no-save --dry-run --lockfile --force --cache-dir --no-cache --silent --verbose --global --cwd --backend --link-native-bins --help";
PACKAGE_OPTIONS[SHARED_OPTIONS_SHORT]="-c -y -p -f -g";
+ PM_OPTIONS[LONG_OPTIONS]="--config --yarn --production --no-save --dry-run --lockfile --force --cache-dir --no-cache --silent --verbose --no-progress --no-summary --no-verify --ignore-scripts --global --cwd --backend --link-native-bins --help"
+ PM_OPTIONS[SHORT_OPTIONS]="-c -y -p -f -g"
+
local cur_word="${COMP_WORDS[${COMP_CWORD}]}";
local prev="${COMP_WORDS[$(( COMP_CWORD - 1 ))]}";
@@ -150,6 +153,11 @@ _bun_completions() {
COMPREPLY+=( $(compgen -W "--version --cwd --help --silent -v -h" -- "${cur_word}" ) );
_read_scripts_in_package_json;
return;;
+ pm)
+ _long_short_completion \
+ "${PM_OPTIONS[LONG_OPTIONS]} ${PM_OPTIONS[SHORT_OPTIONS]}";
+ COMPREPLY+=( $(compgen -W "bin ls cache hash hash-print hash-string" -- "${cur_word}") );
+ return;;
*)
local replaced_script;
_long_short_completion \
diff --git a/completions/bun.fish b/completions/bun.fish
index 57c42cc79..2158790a5 100644
--- a/completions/bun.fish
+++ b/completions/bun.fish
@@ -53,14 +53,17 @@ end
set -l bun_install_boolean_flags yarn production optional development no-save dry-run force no-cache silent verbose global
set -l bun_install_boolean_flags_descriptions "Write a yarn.lock file (yarn v1)" "Don't install devDependencies" "Add dependency to optionalDependencies" "Add dependency to devDependencies" "Don't install devDependencies" "Don't install anything" "Always request the latest versions from the registry & reinstall all dependenices" "Ignore manifest cache entirely" "Don't output anything" "Excessively verbose logging" "Use global folder"
-set -l bun_builtin_cmds dev create help bun upgrade discord run install remove add init link unlink
-set -l bun_builtin_cmds_without_run dev create help bun upgrade discord install remove add init
-set -l bun_builtin_cmds_without_bun dev create help upgrade run discord install remove add init
-set -l bun_builtin_cmds_without_create dev help bun upgrade discord run install remove add init
-set -l bun_builtin_cmds_without_install create dev help bun upgrade discord run remove add init
-set -l bun_builtin_cmds_without_remove create dev help bun upgrade discord run install add init
-set -l bun_builtin_cmds_without_add create dev help bun upgrade discord run remove install init
-set -l bun_builtin_cmds_without_pm create dev help bun upgrade discord run init
+set -l bun_builtin_cmds dev create help bun upgrade discord run install remove add init link unlink pm x
+set -l bun_builtin_cmds_without_run dev create help bun upgrade discord install remove add init pm x
+set -l bun_builtin_cmds_without_bun dev create help upgrade run discord install remove add init pm x
+set -l bun_builtin_cmds_without_create dev help bun upgrade discord run install remove add init pm x
+set -l bun_builtin_cmds_without_install create dev help bun upgrade discord run remove add init pm x
+set -l bun_builtin_cmds_without_remove create dev help bun upgrade discord run install add init pm x
+set -l bun_builtin_cmds_without_add create dev help bun upgrade discord run remove install init pm x
+set -l bun_builtin_cmds_without_pm create dev help bun upgrade discord run init pm x
+
+# clear
+complete -e -c bun
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_run; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a '(__fish__get_bun_scripts)' -d 'script'
@@ -102,7 +105,7 @@ complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a '--help' -d 'See all commands and flags' -x
complete -c bun \
- -n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -l "version" -s "v" -a '--version' -d 'bun\'s version' -x
+ -n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -l "version" -s "v" -a '--version' -d 'Bun\'s version' -x
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a 'discord' -d 'Open bun\'s Discord server' -x
@@ -150,5 +153,11 @@ complete -c bun \
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from add;" -d 'History' -a '(__history_completions)'
+
+complete -c bun \
+ -n "__fish_seen_subcommand_from pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) cache;" -a 'bin ls cache hash hash-print hash-string' -f
+
+complete -c bun \
+ -n "__fish_seen_subcommand_from pm; and __fish_seen_subcommand_from cache; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts);" -a 'rm' -f
-complete -c bun --no-files \ No newline at end of file
+complete -c bun -n "not __fish_seen_subcommand_from $bun_builtin_cmds (__fish__get_bun_bins) (__fish__get_bun_scripts)" -a "$bun_builtin_cmds" -f \ No newline at end of file
diff --git a/completions/bun.zsh b/completions/bun.zsh
index 287c41b77..5d1686404 100644
--- a/completions/bun.zsh
+++ b/completions/bun.zsh
@@ -23,7 +23,7 @@ _bun() {
scripts="scripts:scripts:(($scripts_list))"
IFS=$'\n' files_list=($(SHELL=zsh bun getcompletes j))
- main_commands=('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" remove\:"Remove a dependency from package.json" run\:"Run a script or package bin" upgrade\:"Upgrade to the latest version of bun"')
+ main_commands=('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" x\:"Run a command from a local or remote NPM package" 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"')
main_commands=($main_commands)
_alternative "$scripts" "args:command:(($main_commands))" "files:files:(($files_list))"
;;
@@ -263,7 +263,83 @@ _bun() {
;;
- help)
+ x)
+ _arguments -s -C \
+ '1: :->cmd' \
+ '2: :->cmd2' \
+ '*: :->args' &&
+ ret=0
+ ;;
+ pm)
+
+ pmargs=('-c[Load config (bunfig.toml)]'
+ '--config[Load config (bunfig.toml)]'
+ '-y[Write a yarn.lock file (yarn v1)]'
+ '--yarn[Write a yarn.lock file (yarn v1)]'
+ '-p[Do not install devDependencies]'
+ '--production[Do not install devDependencies]'
+ '--no-save[Do not save a lockfile]'
+ '--dry-run[Do not install anything]'
+ '--lockfile[Store & load a lockfile at a specific filepath]'
+ '-f[Always request the latest versions from the registry & reinstall all dependencies]'
+ '--force[Always request the latest versions from the registry & reinstall all dependencies]'
+ '--cache-dir[Store & load cached data from a specific directory path]'
+ '--no-cache[Ignore manifest cache entirely]'
+ '--silent[Do not log anything]'
+ '--verbose[Excessively verbose logging]'
+ '--no-progress[Disable the progress bar]'
+ '--no-summary[Do not print a summary]'
+ '--no-verify[Skip verifying integrity of newly downloaded packages]'
+ '--ignore-scripts[Skip lifecycle scripts in the package.json (dependency scripts are never run)]'
+ '-g[Install globally]'
+ '--global[Install globally]'
+ '--cwd[Set a specific cwd]'
+ '--backend[Platform-specific optimizations for installing dependencies. Possible values: "clonefile" (default), "hardlink", "symlink", "copyfile"]'
+ '--link-native-bins[Link "bin" from a matching platform-specific "optionalDependencies" instead. Default: esbuild, turbo]'
+ '--help[Print this help menu]'
+ )
+
+ # ---- Command: help
+ _arguments -s -C \
+ '1: :->cmd' \
+ '2: :->cmd2' \
+ '*: :->args' &&
+ ret=0
+
+ case $state in
+ cmd2)
+ _alternative 'args:cmd3:((bin ls cache hash hash-print hash-string))'
+ ;;
+
+ args)
+
+ case $line[2] in
+ cache)
+
+ _arguments -s -C \
+ '1: :->cmd' \
+ '2: :->cmd2' \
+ ':::(rm)' \
+ $pmargs &&
+ ret=0
+ ;;
+ *)
+
+ _arguments -s -C \
+ '1: :->cmd' \
+ '2: :->cmd2' \
+ $pmargs &&
+ ret=0
+ ;;
+ esac
+ ;;
+
+ esac
+ ;;
+
+ \
+ \
+ help)
# ---- Command: help
_arguments -s -C \
diff --git a/src/cli.zig b/src/cli.zig
index 0e0e6a6a4..2f0a7dd26 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -960,6 +960,8 @@ pub const Command = struct {
"bun",
"upgrade",
"discord",
+ "pm",
+ "x",
};
const reject_list = default_completions_list ++ [_]string{