Improve completion when '--cwd' is specified
This commit is contained in:
parent
4601310ac2
commit
44e1c1ed9c
13
src/_yarn
13
src/_yarn
|
@ -85,7 +85,12 @@ _global_commands=(
|
||||||
|
|
||||||
_yarn_commands_scripts() {
|
_yarn_commands_scripts() {
|
||||||
local -a scripts
|
local -a scripts
|
||||||
scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
|
if [[ -n $opt_args[--cwd] ]]; then
|
||||||
|
scripts=($(cd $opt_args[--cwd] && yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
|
||||||
|
else
|
||||||
|
scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
|
||||||
|
fi
|
||||||
|
|
||||||
_describe 'command or script' _commands -- _global_commands -- scripts
|
_describe 'command or script' _commands -- _global_commands -- scripts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +99,11 @@ _yarn_scripts() {
|
||||||
local -a scriptNames scriptCommands
|
local -a scriptNames scriptCommands
|
||||||
local i runJSON
|
local i runJSON
|
||||||
|
|
||||||
runJSON=$(yarn run --json 2>/dev/null)
|
if [[ -n $opt_args[--cwd] ]]; then
|
||||||
|
runJSON=$(cd $opt_args[--cwd] && yarn run --json 2>/dev/null)
|
||||||
|
else
|
||||||
|
runJSON=$(yarn run --json 2>/dev/null)
|
||||||
|
fi
|
||||||
# Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
|
# Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
|
||||||
# pattern as a newline. See https://superuser.com/q/307165
|
# pattern as a newline. See https://superuser.com/q/307165
|
||||||
binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
|
binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
|
||||||
|
|
Loading…
Reference in New Issue