Use jq to iterate over installed dependencies for yarn completions

Only if available, else fall back to fragile package.json parsing.
This commit is contained in:
Mahmoud Al-Qudsi 2018-04-19 18:15:33 -05:00
parent e48722f0bf
commit 5f82cb5ca4

View file

@ -38,34 +38,37 @@ function __yarn_installed_packages
return 1 return 1
end end
# todo: if jq exists, use it instead and use what's below as a fallback only if type -q jq
set -l depsFound 0 jq -r '.dependencies | to_entries[] | .key' bower.json
for line in (cat $package_json) else
# echo "evaluating $line" set -l depsFound 0
if test $depsFound -eq 0 for line in (cat $package_json)
# echo "mode: noDeps" # echo "evaluating $line"
if string match -qr '(devD|d)ependencies"' -- $line if test $depsFound -eq 0
# echo "switching to mode: deps" # echo "mode: noDeps"
set depsFound 1 if string match -qr '(devD|d)ependencies"' -- $line
# echo "switching to mode: deps"
set depsFound 1
continue
end
continue continue
end end
continue
if string match -qr '\}' -- $line
# echo "switching to mode: noDeps"
set depsFound 0
continue
end
# echo "mode: deps"
string replace -r '^\s*"([^"]+)".*' '$1' -- $line
end end
if string match -qr '\}' -- $line
# echo "switching to mode: noDeps"
set depsFound 0
continue
end
# echo "mode: deps"
string replace -r '^\s*"([^"]+)".*' '$1' -- $line
end end
end end
complete -f -c yarn -n '__fish_seen_subcommand_from remove' -a '(__yarn_installed_packages)' complete -f -c yarn -n '__fish_seen_subcommand_from remove' -xa '(__yarn_installed_packages)'
complete -f -c yarn -n '__fish_seen_subcommand_from add' -a '(__yarn_filtered_list_packages)' complete -f -c yarn -n '__fish_seen_subcommand_from add' -a '(__yarn_filtered_list_packages)'
complete -f -c yarn -n '__fish_use_subcommand' -a help complete -f -c yarn -n '__fish_use_subcommand' -a help