plugin/projects: refactor a bit
parent
1ec48c8d71
commit
a78d72eed1
|
|
@ -8,25 +8,33 @@ function pj() {
|
||||||
group 'projects'
|
group 'projects'
|
||||||
|
|
||||||
local proj="${1?${FUNCNAME[0]}: project name required}"
|
local proj="${1?${FUNCNAME[0]}: project name required}"
|
||||||
local cmd PS3 dest
|
local cmd PS3 dest d
|
||||||
local -a dests=()
|
local -a dests
|
||||||
|
|
||||||
if [[ "$proj" == "open" ]]; then
|
if [[ "$proj" == "open" ]]; then
|
||||||
shift
|
shift
|
||||||
|
proj="${1}"
|
||||||
cmd="${EDITOR?}"
|
cmd="${EDITOR?}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# collect possible destinations to account for directories
|
# collect possible destinations to account for directories
|
||||||
# with the same name in project directories
|
# with the same name in project directories
|
||||||
IFS=':' read -ra dests <<< "${BASH_IT_PROJECT_PATHS}"
|
IFS=':' read -ra dests <<< "${BASH_IT_PROJECT_PATHS?${FUNCNAME[0]}: project working folders must be configured}"
|
||||||
|
for d in "${!dests[@]}"; do
|
||||||
|
if [[ ! -d "${dests[d]}" ]]; then
|
||||||
|
unset 'dests[d]'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# when multiple destinations are found, present a menu
|
case ${#dests[@]} in
|
||||||
if [[ ${#dests[@]} -eq 0 ]]; then
|
0)
|
||||||
_log_error "no such project '${1:-}'"
|
_log_error "BASH_IT_PROJECT_PATHS must contain at least one existing location"
|
||||||
return 1
|
return 1
|
||||||
elif [[ ${#dests[@]} -eq 1 ]]; then
|
;;
|
||||||
dest="${dests[0]}"
|
1)
|
||||||
elif [[ ${#dests[@]} -gt 1 ]]; then
|
dest="${dests[*]}/${proj}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
PS3="Multiple project directories found. Please select one: "
|
PS3="Multiple project directories found. Please select one: "
|
||||||
dests+=("cancel")
|
dests+=("cancel")
|
||||||
select d in "${dests[@]}"; do
|
select d in "${dests[@]}"; do
|
||||||
|
|
@ -35,15 +43,13 @@ function pj() {
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
dest=$d
|
dest="${d}/${proj}"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
else
|
;;
|
||||||
_log_error "please report this error"
|
esac
|
||||||
return 2 # should never reach this
|
|
||||||
fi
|
|
||||||
|
|
||||||
"${cmd:-cd}" "${dest}"
|
"${cmd:-cd}" "${dest}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue