Skip to content

Instantly share code, notes, and snippets.

@Leko
Created February 11, 2019 06:29
Show Gist options
  • Save Leko/a55b482b7f2d1da4617e61a8a9af4895 to your computer and use it in GitHub Desktop.
Save Leko/a55b482b7f2d1da4617e61a8a9af4895 to your computer and use it in GitHub Desktop.
Search and change directory with peco in monorepo
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