commit f583dee98fa19c700e0fc6b5bd86dc1abe173b6f
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2021-09-27T12:27:27Z |
| subject | Improved go command with exclude options |
commit f583dee98fa19c700e0fc6b5bd86dc1abe173b6f
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2021-09-27T12:27:27Z
Improved go command with exclude options
---
bash/bashrc/sources/40_go-command | 60 ++++++++++++++++++++++++++++-----------
1 file changed, 43 insertions(+), 17 deletions(-)
diff --git a/bash/bashrc/sources/40_go-command b/bash/bashrc/sources/40_go-command
index 1b5b492..8e20a1f 100755
--- a/bash/bashrc/sources/40_go-command
+++ b/bash/bashrc/sources/40_go-command
@@ -1,6 +1,32 @@
#!/bin/bash
# go command
+function _begin_sel() {
+ _selected=
+ _sel_len=${#_sel_args[@]}
+ if [ $_sel_len -gt 1 ]; then
+ echo "There are $_sel_len possible paths under $1@[$2]"
+ j=1
+ for i in ${_sel_args[@]}; 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
+ _selected=${_sel_args[$(( num - 1 ))]}
+ return 0
+ fi
+
+ _selected=${_sel_args[0]}
+ return 0
+}
+
function go() {
ARG1=$1; ARG2=$2; ARG3=$3;
@@ -45,7 +71,10 @@ function go() {
return 1
fi
- SITE=$( ls "$UDEV" | grep -m 1 "$ARG2" )
+ _sel_args=( $( ls "$UDEV" | grep "$ARG2" ) )
+ _begin_sel $UDEV $ARG2
+
+ SITE=$_selected
if [[ -z "$SITE" ]]; then
echo "No such site: $ARG2"
find "$UDEV/" -maxdepth 1 -type d | sed "s/^.\+\/\([^\/]\+\)\/\?$/ \1/g"
@@ -90,21 +119,11 @@ function go() {
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 ))]}
+ _sel_args=$CHOICES
+ if [ -z $_selected ]; then
+ return 1
+ fi
+ LOCATION=$_selected
fi
fi
break
@@ -135,13 +154,20 @@ __dive() {
return $?
fi
+ _EXCLUDE_ARGS=
+ if [ -n $EXCLUDE_DIRS ]; then
+ for i in ${EXCLUDE_DIRS[@]}; do
+ _EXCLUDE_ARGS="$_EXCLUDE_ARGS -path '*/$i' -prune -o -name $i -prune -o"
+ done
+ fi
+
OIFS=$IFS
IFS="*"
PATT="*$**"
IFS=$OIFS
pushd "$WDIR" > /dev/null
- DIR=$(find . -type d -path "$PATT" -print -quit | cut -c 3- )
+ DIR=$(find . $_EXCLUDE_ARGS -path "$PATT" -type d -print -quit | cut -c 3- )
popd > /dev/null
if [[ -z $DIR ]]; then