Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# yarn-completion ![](https://github.com/dsifford/yarn-completion/workflows/build/badge.svg)

> Bash ^4.x completion for [Yarn](https://github.com/yarnpkg/yarn)
> Bash ^4.x completion for [Yarn CLI 4.x](https://yarnpkg.com/cli)

## Installation on Debian Linux

Just grab the file and move it to bash completion global folder:

```shell
wget https://raw.githubusercontent.com/ildella/yarn-completion/master/yarn-completion.bash yarn-completion.bash
sudo mv yarn-completion.bash /etc/bash_completion.d
```

## Installation

Expand All @@ -9,10 +18,11 @@ To enable on-demand completion loading, download the completion file to the pred
```sh
mkdir -p "${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions/"
curl -o "${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions/yarn" \
https://raw.githubusercontent.com/dsifford/yarn-completion/master/yarn-completion.bash
https://raw.githubusercontent.com/ildella/yarn-completion/master/yarn-completion.bash
```

### Installation on macOS with Homebrew

To use this script on macOS, we need to install [bash](https://www.gnu.org/software/bash/) and [bash-completion](https://github.com/scop/bash-completion) in addition to the above script.

1. `bash` version ^4.x.x is **required**.
Expand Down
72 changes: 13 additions & 59 deletions yarn-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,9 @@ _yarn_config() {
((depth++))
declare cmd
declare subcommands=(
delete
get
list
set
unset
)
declare known_keys=(
ignore-optional
Expand Down Expand Up @@ -477,7 +476,6 @@ _yarn_global() {
bin
list
remove
upgrade
upgrade-interactive
)
cmdlist="@($(tr ' ' '|' <<< "${subcommands[*]}"))"
Expand Down Expand Up @@ -843,42 +841,6 @@ _yarn_unplug() {
return 1
}

_yarn_upgrade() {
((depth++))
declare cmd dependencies devDependencies
flags=(
--audit -A
--caret -C
--exact -E
--latest -L
--pattern -P
--scope -S
--tilde -T
)
__yarn_get_command -d 1
case "$cmd" in
global)
dependencies=$(__yarn_get_package_fields -g dependencies)
devDependencies=''
;;
upgrade)
dependencies=$(__yarn_get_package_fields dependencies)
devDependencies=$(__yarn_get_package_fields devDependencies)
;;
*)
return 1
;;
esac
case "$cur" in
-*) ;;
*)
COMPREPLY=($(compgen -W "$dependencies $devDependencies" -- "$cur"))
return 0
;;
esac
return 1
}

_yarn_upgrade_interactive() {
((depth++))
flags=(
Expand Down Expand Up @@ -1029,44 +991,36 @@ _yarn() {
declare -a words
declare -i cword counter=1 depth=1
declare -ar commands=(
access
add
audit
autoclean
bin
cache
check
config
constraints
create
dedupe
dix
exec
generate-lock-entry
global
help
import
explain
info
init
install
licenses
link
list
login
logout
node
outdated
owner
npm
pack
policies
publish
patch-commit
patch
plugin
rebuild
remove
run
tag
team
search
set
stage
unlink
unplug
upgrade
upgrade-interactive
version
versions
why
workspace
workspaces
Expand Down