-
Notifications
You must be signed in to change notification settings - Fork 21
/
.zoom
79 lines (70 loc) · 1.62 KB
/
.zoom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
# Usage: export LERNA=pwd ; source ./.zoom
ROOT="$LERNA/packages"
# Copyright Josh Clyde (c) 2017
# https://github.com/joshclyde/ez_lerna_helper
# source this file to add an easy way to navigate between lerna packages.
function z() {
if [ -z "$1" ]
then
echo "🚀 Zooooooming to your lerna repo..."
cd $LERNA
return
fi
shopt -s nullglob
array=($(ls "$ROOT/"))
shopt -u nullglob # Turn off nullglob to make sure it doesn't interfere with anything later
MATCHES=()
counter=0
for i in "${array[@]}"
do
if [[ $i =~ .*$1.* && ( -z "$2" || $i =~ .*$2.* ) ]]
then
MATCHES+=($i)
counter=$((counter+1))
PROJ="$i"
fi
done
if [ "$counter" -eq "0" ]
then
echo "None of the packages contained '$1' in their name."
return
elif [ "$counter" -eq "1" ]
then
echo "🚀 Zooooooming to $PROJ..."
cd $ROOT/$PROJ
else
if [ ! -z "$2" ]
then
echo "$counter packages contain '$1' and '$2' in their name."
else
echo "$counter packages contain '$1' in their name."
fi
echo ""
echo " 0 -> exit"
counter_2=1
for i in "${MATCHES[@]}"
do
echo " $counter_2 -> $i"
counter_2=$((counter_2+1))
done
read -n 1 -p "Zoom to -> " userinput
echo ""
re='^[0-9]+$'
if ! [[ $userinput =~ $re ]] ; then
return
fi
if [ "$userinput" -eq "0" ]
then
return
fi
echo ""
userinput=$((userinput-1))
if [ -z "${MATCHES[$userinput]}" ]
then
return
fi
echo "🚀 Zooooooming to ${MATCHES[$userinput]}..."
cd $ROOT/${MATCHES[$userinput]}
fi
}