Created
February 11, 2019 06:29
-
-
Save Leko/a55b482b7f2d1da4617e61a8a9af4895 to your computer and use it in GitHub Desktop.
Search and change directory with peco in monorepo
This file contains 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
peco_monorepo() { | |
local module_paths=($(node -e 'console.log(module.paths.join(" "))')) | |
local found=0 | |
for module_paths in ${module_paths[@]} | |
do | |
local lerna_bin="$module_paths/.bin/lerna" | |
if [ ! -f $lerna_bin ]; then | |
continue | |
fi | |
found=1 | |
local selected | |
selected="$($lerna_bin ls --all --json | jq -r .[].location | peco --null)" | |
if [ -n "$selected" ]; then | |
cd $selected | |
fi | |
done | |
if [ "$found" = "0" ]; then | |
echo "Current working directory ($(pwd)) is outside a monorepo" >&2 | |
fi | |
} | |
bind -x '"\C-[\C-]": peco_monorepo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment