好用的godir
在android裡面的 envsetup.sh 提供的函式,可以直接打 godir XXX,就可以直接列出檔名中含有XXX的路徑讓你選擇切換。
但他只能用在android project的目錄下,因為我有多個project的路徑,所以只好改為自己來用,主要是找到頂層目錄的,下面的"bootable/bootloader"代表你的頂層目錄下會含有這個子目錄~
function gettopj
{
local TOPFILE=$1
while [ $PWD != "/" ]
do
if [ -n "$PWD" -a -e "$PWD/$TOPFILE" ] ; then
echo $PWD
return
fi
cd ..
done
}
function godirj () {
if [[ -z "$1" ]]; then
echo "Usage: godir"
return
fi
TOPFILE="bootable/bootloader"
T=$(gettopj $TOPFILE)
if [ -z $T ]; then
echo "Cannot find the root directory which contains '$TOPFILE'"
return
fi
if [[ ! -f $T/filelist ]]; then
echo -n "Creating index..."
(cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
echo " Done"
echo ""
fi
local lines
lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
if [[ ${#lines[@]} = 0 ]]; then
echo "Not found"
return
fi
local pathname
local choice
if [[ ${#lines[@]} > 1 ]]; then
while [[ -z "$pathname" ]]; do
local index=1
local line
for line in ${lines[@]}; do
printf "%6s %s\n" "[$index]" $line
index=$(($index + 1))
done
echo
echo -n "Select one: "
unset choice
read choice
if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
echo "Invalid choice"
continue
fi
pathname=${lines[$(($choice-1))]}
done
else
pathname=${lines[0]}
fi
cd $T/$pathname
}
但他只能用在android project的目錄下,因為我有多個project的路徑,所以只好改為自己來用,主要是找到頂層目錄的,下面的"bootable/bootloader"代表你的頂層目錄下會含有這個子目錄~
function gettopj
{
local TOPFILE=$1
while [ $PWD != "/" ]
do
if [ -n "$PWD" -a -e "$PWD/$TOPFILE" ] ; then
echo $PWD
return
fi
cd ..
done
}
function godirj () {
if [[ -z "$1" ]]; then
echo "Usage: godir
return
fi
TOPFILE="bootable/bootloader"
T=$(gettopj $TOPFILE)
if [ -z $T ]; then
echo "Cannot find the root directory which contains '$TOPFILE'"
return
fi
if [[ ! -f $T/filelist ]]; then
echo -n "Creating index..."
(cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
echo " Done"
echo ""
fi
local lines
lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
if [[ ${#lines[@]} = 0 ]]; then
echo "Not found"
return
fi
local pathname
local choice
if [[ ${#lines[@]} > 1 ]]; then
while [[ -z "$pathname" ]]; do
local index=1
local line
for line in ${lines[@]}; do
printf "%6s %s\n" "[$index]" $line
index=$(($index + 1))
done
echo
echo -n "Select one: "
unset choice
read choice
if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
echo "Invalid choice"
continue
fi
pathname=${lines[$(($choice-1))]}
done
else
pathname=${lines[0]}
fi
cd $T/$pathname
}
留言