File tree Expand file tree Collapse file tree 1 file changed +34
-28
lines changed Expand file tree Collapse file tree 1 file changed +34
-28
lines changed Original file line number Diff line number Diff line change @@ -8,42 +8,48 @@ function pj() {
8
8
group ' projects'
9
9
10
10
local proj=" ${1?${FUNCNAME[0]} : project name required} "
11
- local cmd PS3 dest
12
- local -a dests=()
11
+ local cmd PS3 dest d
12
+ local -a dests
13
13
14
14
if [[ " $proj " == " open" ]]; then
15
15
shift
16
+ proj=" ${1} "
16
17
cmd=" ${EDITOR?} "
17
18
fi
18
19
19
20
# collect possible destinations to account for directories
20
21
# with the same name in project directories
21
- IFS=' :' read -ra dests <<< " ${BASH_IT_PROJECT_PATHS}"
22
-
23
- # when multiple destinations are found, present a menu
24
- if [[ ${# dests[@]} -eq 0 ]]; then
25
- _log_error " no such project '${1:- } '"
26
- return 1
27
- elif [[ ${# dests[@]} -eq 1 ]]; then
28
- dest=" ${dests[0]} "
29
- elif [[ ${# dests[@]} -gt 1 ]]; then
30
- PS3=" Multiple project directories found. Please select one: "
31
- dests+=(" cancel" )
32
- select d in " ${dests[@]} " ; do
33
- case $d in
34
- " cancel" )
35
- return
36
- ;;
37
- * )
38
- dest=$d
39
- break
40
- ;;
41
- esac
42
- done
43
- else
44
- _log_error " please report this error"
45
- return 2 # should never reach this
46
- fi
22
+ IFS=' :' read -ra dests <<< " ${BASH_IT_PROJECT_PATHS?${FUNCNAME[0]}: project working folders must be configured}"
23
+ for d in " ${! dests[@]} " ; do
24
+ if [[ ! -d " ${dests[d]} " ]]; then
25
+ unset ' dests[d]'
26
+ fi
27
+ done
28
+
29
+ case ${# dests[@]} in
30
+ 0)
31
+ _log_error " BASH_IT_PROJECT_PATHS must contain at least one existing location"
32
+ return 1
33
+ ;;
34
+ 1)
35
+ dest=" ${dests[*]} /${proj} "
36
+ ;;
37
+ * )
38
+ PS3=" Multiple project directories found. Please select one: "
39
+ dests+=(" cancel" )
40
+ select d in " ${dests[@]} " ; do
41
+ case $d in
42
+ " cancel" )
43
+ return
44
+ ;;
45
+ * )
46
+ dest=" ${d} /${proj} "
47
+ break
48
+ ;;
49
+ esac
50
+ done
51
+ ;;
52
+ esac
47
53
48
54
" ${cmd:- cd} " " ${dest} "
49
55
}
You can’t perform that action at this time.
0 commit comments