Last active
June 29, 2019 17:56
-
-
Save kvendrik/a503c9d3abdd15b786bc9c298f94bb35 to your computer and use it in GitHub Desktop.
Medium article: Yarn Run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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