Improved go command with exclude options
This commit is contained in:
parent
7bcc28f3ba
commit
f583dee98f
@ -1,6 +1,32 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# go command
|
# 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() {
|
function go() {
|
||||||
ARG1=$1; ARG2=$2; ARG3=$3;
|
ARG1=$1; ARG2=$2; ARG3=$3;
|
||||||
|
|
||||||
@ -45,7 +71,10 @@ function go() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SITE=$( ls "$UDEV" | grep -m 1 "$ARG2" )
|
_sel_args=( $( ls "$UDEV" | grep "$ARG2" ) )
|
||||||
|
_begin_sel $UDEV $ARG2
|
||||||
|
|
||||||
|
SITE=$_selected
|
||||||
if [[ -z "$SITE" ]]; then
|
if [[ -z "$SITE" ]]; then
|
||||||
echo "No such site: $ARG2"
|
echo "No such site: $ARG2"
|
||||||
find "$UDEV/" -maxdepth 1 -type d | sed "s/^.\+\/\([^\/]\+\)\/\?$/ \1/g"
|
find "$UDEV/" -maxdepth 1 -type d | sed "s/^.\+\/\([^\/]\+\)\/\?$/ \1/g"
|
||||||
@ -90,21 +119,11 @@ function go() {
|
|||||||
elif [[ $j -eq 2 ]]; then
|
elif [[ $j -eq 2 ]]; then
|
||||||
LOCATION=$__LOC
|
LOCATION=$__LOC
|
||||||
else
|
else
|
||||||
echo "There are $(( j - 1 )) possible paths for ->> $@"
|
_sel_args=$CHOICES
|
||||||
j=1
|
if [ -z $_selected ]; then
|
||||||
for i in ${CHOICES[@]}; do
|
return 1
|
||||||
echo " $j. $i"
|
fi
|
||||||
j=$(( j + 1 ))
|
LOCATION=$_selected
|
||||||
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
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
@ -135,13 +154,20 @@ __dive() {
|
|||||||
return $?
|
return $?
|
||||||
fi
|
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
|
OIFS=$IFS
|
||||||
IFS="*"
|
IFS="*"
|
||||||
PATT="*$**"
|
PATT="*$**"
|
||||||
IFS=$OIFS
|
IFS=$OIFS
|
||||||
|
|
||||||
pushd "$WDIR" > /dev/null
|
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
|
popd > /dev/null
|
||||||
|
|
||||||
if [[ -z $DIR ]]; then
|
if [[ -z $DIR ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user