Added Path choices for go command

This commit is contained in:
斟酌 鵬兄 2018-01-31 17:59:49 +08:00
parent 0335ec832a
commit 78e9854453

View File

@ -57,17 +57,64 @@ function go() {
return $? return $?
fi fi
__SFT23=0
for ((i = 0; i < ${#LOCS[@]}; i++)) for ((i = 0; i < ${#LOCS[@]}; i++))
do do
LOC=${LOCS[i]} LOC=${LOCS[i]}
LOCATION=$(ls -d "$UDEV/$SITE/$LOC/"*"$ARG3"*/ 2> /dev/null ) LOCATION=$(ls -d "$UDEV/$SITE/$LOC/"*"$ARG3"*/ 2> /dev/null )
if [[ -n "$LOCATION" ]]; then if [[ -n "$LOCATION" ]]; then
NPATHS=$( echo -n "$LOCATION" | grep -c '^' )
if [[ $NPATHS -gt 1 ]]; then
# shift ARG2 ARG3
shift; shift
__SFT23=1
j=1
CHOICES=()
__CC=$CC
for i in ${LOCATION[@]}; do
__dive "test -d" "$i" $@ > /dev/null
if [[ $? -eq 0 ]]; then
__LOC="$i"
CHOICES+=($i)
j=$(( j + 1 ))
fi
done
CC=$__CC
# No possible solution for this path
if [[ $j -eq 1 ]]; then
echo "Unable to trace \"$@\" under $UDEV/$SITE/*$ARG3*/"
return 1
elif [[ $j -eq 2 ]]; then
LOCATION=$__LOC
else
echo "There are $(( j - 1 )) possible paths for ->> $@"
j=1
for i in ${CHOICES[@]}; do
echo " $j. $i"
j=$(( j + 1 ))
done
echo -n "Your choice [1-$(( j - 1 ))]: "
read num
re="^[1-$(( j - 1 ))]+\$"
if [[ ! $num =~ $re ]]; then
echo "Value does not fall into expected range"
return 1
fi
LOCATION=${CHOICES[$(( num - 1 ))]}
fi
fi
break break
fi fi
done done
if [[ $__SFT23 -eq 0 ]]; then
# shift ARG2 ARG3 # shift ARG2 ARG3
shift; shift shift; shift
fi
if [[ -n "$LOCATION" ]]; then if [[ -n "$LOCATION" ]]; then
__dive $CC "$LOCATION" $@ __dive $CC "$LOCATION" $@