search/index fixes

warning if mlocate not found and better search string handling
searches through all open tombs. mlocate seems to not support multiple strings well.
This commit is contained in:
Jaromil 2013-06-11 16:49:58 +00:00
parent f43ab33872
commit 6e51d166be

34
tomb
View File

@ -1533,7 +1533,15 @@ BEGIN { main="" }
# $1 is optional, to specify a tomb # $1 is optional, to specify a tomb
index_tombs() { index_tombs() {
{ command -v updatedb > /dev/null } || { { command -v updatedb > /dev/null } || {
die "Cannot index tombs on this system: updatedb not installed" } die "Cannot index tombs on this system: updatedb (mlocate) not installed" }
updatedbver=`updatedb --version | grep '^updatedb'`
[[ "$updatedbver" =~ "GNU findutils" ]] && {
_warning "Cannot use GNU findutils for index/search commands" }
[[ "$updatedbver" =~ "mlocate" ]] || {
die "Index command needs 'mlocate' to be installed." }
xxx "$updatedbver"
mounted_tombs=(`list_tomb_mounts $1`) mounted_tombs=(`list_tomb_mounts $1`)
{ test ${#mounted_tombs} = 0 } && { { test ${#mounted_tombs} = 0 } && {
@ -1557,14 +1565,22 @@ index_tombs() {
} }
search_tombs() { search_tombs() {
{ command -v locate > /dev/null } || { { command -v locate > /dev/null } || {
die "Cannot index tombs on this system: updatedb not installed" } die "Cannot index tombs on this system: updatedb (mlocate) not installed" }
updatedbver=`updatedb --version | grep '^updatedb'`
[[ "$updatedbver" =~ "GNU findutils" ]] && {
_warning "Cannot use GNU findutils for index/search commands" }
[[ "$updatedbver" =~ "mlocate" ]] || {
die "Index command needs 'mlocate' to be installed." }
xxx "$updatedbver"
# list all open tombs # list all open tombs
mounted_tombs=(`list_tomb_mounts $1`) mounted_tombs=(`list_tomb_mounts`)
{ test ${#mounted_tombs} = 0 } && { if [ ${#mounted_tombs} = 0 ]; then
die "I can't see any open tomb, may they all rest in peace." } die "I can't see any open tomb, may they all rest in peace."; fi
shift
yes "Searching for: $fg_bold[white]${=@}$fg_no_bold[white]" yes "Searching for: $fg_bold[white]${(f)@}$fg_no_bold[white]"
for t in ${mounted_tombs}; do for t in ${mounted_tombs}; do
xxx "checking for index: ${t}" xxx "checking for index: ${t}"
mapper=`basename ${t[(ws:;:)1]}` mapper=`basename ${t[(ws:;:)1]}`
@ -1572,8 +1588,8 @@ search_tombs() {
tombmount=${t[(ws:;:)2]} tombmount=${t[(ws:;:)2]}
if [ -r ${tombmount}/.updatedb ]; then if [ -r ${tombmount}/.updatedb ]; then
say "Searching in tomb $tombname" say "Searching in tomb $tombname"
locate -d ${tombmount}/.updatedb -e -i ${=@} locate -d ${tombmount}/.updatedb -e -i "${(f)@}"
say "Matches found: `locate -d ${tombmount}/.updatedb -e -i -c ${=@}`" say "Matches found: `locate -d ${tombmount}/.updatedb -e -i -c ${(f)@}`"
else else
no "skipping tomb $tombname: not indexed" no "skipping tomb $tombname: not indexed"
no "run 'tomb index' to create indexes" no "run 'tomb index' to create indexes"