Skip to content

Commit

Permalink
beefind: bugfix: cutting rootdir before excluding files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Dreyer committed May 22, 2012
1 parent 78cba40 commit 46f9022
Showing 1 changed file with 20 additions and 44 deletions.
64 changes: 20 additions & 44 deletions src/beefind.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ function usage() {
EOF
}

function bee_find() {
function do_beefind() {
local options=$(${BEEGETOPT} --name beefind \
--option cutroot/c \
--option exclude/e= \
--option skiplist/s= \
-- "${@}")
Expand All @@ -66,11 +67,16 @@ function bee_find() {

eval set -- "${options}"

declare find_format="%p\n"
declare -a OPT_EXCLUDE
declare -a OPT_SKIPLIST

while true ; do
case "${1}" in
--cutroot)
find_format="/%P\n"
shift 1
;;
--exclude)
OPT_EXCLUDE=( ${OPT_EXCLUDE:+${OPT_EXCLUDE[@]}} "${2}" )
shift 2
Expand All @@ -86,53 +92,23 @@ function bee_find() {
esac
done

if [ -z "${1}" ] ; then
if [ -z "${@}" ] ; then
usage
exit 1
fi

find ${1} -mindepth 1 | \
grep \
--extended-regexp \
--invert-match \
--file=<(if [ "${#OPT_SKIPLIST[@]}" -gt 0 ] ; then
grep --invert-match --regexp="^ *$" ${OPT_SKIPLIST[@]}
fi) \
--file=<(for p in ${OPT_EXCLUDE[@]} ; do
echo ${p}
done)
}

function do_beefind() {
local options=$(${BEEGETOPT} --name beefind \
--option cutroot/c= \
-- "${@}")

if [ $? != 0 ] ; then
usage
exit 1
fi

eval set -- "${options}"

declare OPT_CUTROOT=

while true ; do
case "${1}" in
--cutroot)
OPT_CUTROOT="${2}"
shift 2
;;
--)
shift
break
;;
esac
done

while read line ; do
echo ${line#${OPT_CUTROOT}}
done < <(bee_find ${@})
dirs=( "${@}" )

grep \
--extended-regexp \
--invert-match \
--file=<(if [ "${#OPT_SKIPLIST[@]}" -gt 0 ] ; then
grep --invert-match --regexp="^ *$" ${OPT_SKIPLIST[@]}
fi) \
--file=<(for p in ${OPT_EXCLUDE[@]} ; do
echo ${p}
done) \
<(find ${dirs[@]} -mindepth 1 -xdev -printf ${find_format})
}

###############################################################################
Expand Down

0 comments on commit 46f9022

Please sign in to comment.