Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Last active June 29, 2019 17:56
Show Gist options
  • Save kvendrik/a503c9d3abdd15b786bc9c298f94bb35 to your computer and use it in GitHub Desktop.
Save kvendrik/a503c9d3abdd15b786bc9c298f94bb35 to your computer and use it in GitHub Desktop.
Medium article: Yarn Run
autoload bashcompinit
bashcompinit
function __find_closest_npm_package {
if [ -f 'package.json' ]; then
echo 'package.json'
return
fi
current_relative_path=''
while [ ! -f "package.json" ]; do
if [[ "$(pwd)" == '/' ]]; then
return
fi
cd ../ || return
current_relative_path="$current_relative_path../"
done
echo "$current_relative_path"package.json
}
function __get_npm_package_scripts_autocomplete {
closest_package_path="$(__find_closest_npm_package)"
if [ -z "$closest_package_path" ]; then
return
fi
COMPREPLY=($(jq '.scripts | keys | join(" ")' "$closest_package_path" | tr -d '"'))
}
function yr {
yarn run $@
}
complete -F __get_npm_package_scripts_autocomplete yr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment