penguin/utils

my env utils

commit 78e9854453d674275316f6afdfa42d757dfd2be2

author斟酌 鵬兄 <tgckpg@gmail.com>
date2018-01-31T09:59:49Z
subjectAdded Path choices for go command
commit 78e9854453d674275316f6afdfa42d757dfd2be2
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2018-01-31T09:59:49Z

    Added Path choices for go command
---
 bash/bashrc/sources/40_go-command | 51 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/bash/bashrc/sources/40_go-command b/bash/bashrc/sources/40_go-command
index 6c2ec67..1b5b492 100755
--- a/bash/bashrc/sources/40_go-command
+++ b/bash/bashrc/sources/40_go-command
@@ -57,17 +57,64 @@ function go() {
         return $?
     fi
 
+    __SFT23=0
     for ((i = 0; i < ${#LOCS[@]}; i++))
     do
         LOC=${LOCS[i]}
         LOCATION=$(ls -d "$UDEV/$SITE/$LOC/"*"$ARG3"*/ 2> /dev/null )
         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
         fi
     done
 
-    # shift ARG2 ARG3
-    shift; shift
+    if [[ $__SFT23 -eq 0 ]]; then
+        # shift ARG2 ARG3
+        shift; shift
+    fi
 
     if [[ -n "$LOCATION" ]]; then
         __dive $CC "$LOCATION" $@