-
Notifications
You must be signed in to change notification settings - Fork 2
/
goto.sh
executable file
·52 lines (45 loc) · 905 Bytes
/
goto.sh
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
#!/usr/bin/env bash
usage='Usage: goto [-c] target'
workspace=${GOTO_WORKSPACE:-$HOME}
ignoreDirs=${GOTO_IGNORE:-'professor-cam'}
mode='cd'
while getopts ":c" opt; do
case ${opt} in
c ) mode='code'
;;
\? ) echo "$usage"
;;
esac
done
if [[ $# > 1 ]]; then
shift $((OPTIND -1))
fi
target=''
for dir in $(ls $workspace); do
if [[ $ignoreDirs =~ $dir ]]; then
continue
fi
dir_initials=''
for word in $(echo $dir | tr '-' ' '); do
dir_initials="$dir_initials${word:0:1}"
done
if [[ $dir_initials == $1 ]]; then
target="$dir"
break
fi
done
if [[ $target == '' ]]; then
case $1 in
'pca' | 'passport-control-activity')
target='passport-control/packages/passport-control-activity'
;;
*)
target=$1
;;
esac
fi
if [[ $mode == 'cd' ]]; then
cd "$workspace/$target"
elif [[ $mode == 'code' ]]; then
code "$workspace/$target"
fi