mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Autocomplete popular package names (thanks @evanwashere)
This commit is contained in:
@@ -16,6 +16,18 @@ function __fish__get_bun_scripts
|
||||
string trim (string split '\n' (string split '\t' (bun getcompletes z)))
|
||||
end
|
||||
|
||||
function __fish__get_bun_packages
|
||||
if test (commandline -ct) != ""
|
||||
set -lx SHELL fish
|
||||
string split ' ' (bun getcompletes a (commandline -ct))
|
||||
end
|
||||
end
|
||||
|
||||
function __history_completions
|
||||
set -l tokens (commandline --current-process --tokenize)
|
||||
history --prefix (commandline) | string replace -r \^$tokens[1]\\s\* "" | string replace -r \^$tokens[2]\\s\* "" | string split ' '
|
||||
end
|
||||
|
||||
function __fish__get_bun_bun_js_files
|
||||
string split ' ' (bun getcompletes j)
|
||||
end
|
||||
@@ -129,9 +141,9 @@ 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 install add remove;" -l 'cache-dir' -d 'Choose a cache directory (default: $HOME/.bun/install/cache)'
|
||||
|
||||
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 remove;" -d "Add a folder to package.json"
|
||||
-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 'Popular' -a '(__fish__get_bun_packages)'
|
||||
|
||||
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;" -F
|
||||
-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 --no-files
|
||||
@@ -55,8 +55,9 @@ _bun() {
|
||||
ret=0
|
||||
|
||||
case $state in
|
||||
package) ;;
|
||||
|
||||
package)
|
||||
_bun_add_param_package_completion
|
||||
;;
|
||||
esac
|
||||
|
||||
;;
|
||||
@@ -497,6 +498,39 @@ _bun_run_param_script_completion() {
|
||||
fi
|
||||
}
|
||||
|
||||
_set_remove() {
|
||||
comm -23 <(echo $1 | sort | tr " " "\n") <(echo $2 | sort | tr " " "\n") 2>/dev/null
|
||||
}
|
||||
|
||||
_bun_add_param_package_completion() {
|
||||
|
||||
IFS=$'\n' inexact=($(history -n bun | grep -E "^bun add " | cut -c 9- | uniq))
|
||||
IFS=$'\n' exact=($($inexact | grep -E "^$words[$CURRENT]"))
|
||||
IFS=$'\n' packages=($(SHELL=zsh bun getcompletes a $words[$CURRENT]))
|
||||
|
||||
to_print=$inexact
|
||||
if [ ! -z "$exact" -a "$exact" != " " ]; then
|
||||
to_print=$exact
|
||||
fi
|
||||
|
||||
if [ ! -z "$to_print" -a "$to_print" != " " ]; then
|
||||
if [ ! -z "$packages" -a "$packages" != " " ]; then
|
||||
_describe -1 -t to_print 'History' to_print
|
||||
_describe -1 -t packages "Popular" packages
|
||||
return
|
||||
fi
|
||||
|
||||
_describe -1 -t to_print 'History' to_print
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -z "$packages" -a "$packages" != " " ]; then
|
||||
_describe -1 -t packages "Popular" packages
|
||||
return
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
__bun_dynamic_comp() {
|
||||
local comp=""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user