mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2025-02-02 11:58:28 +00:00
new index and search commands
now it is possible to index all filenames contained in tombs using updatedb(8) and then automatically search for them using locate in all open tombs. Documentation was updated accordingly.
This commit is contained in:
parent
2b6a38f1d7
commit
12a7760895
19
doc/tomb.1
19
doc/tomb.1
@ -73,12 +73,25 @@ options (default: rw,noatime,nodev).
|
||||
|
||||
.B
|
||||
.IP "list"
|
||||
|
||||
List all the tombs found open, including information about the time
|
||||
they were opened and the hooks that they mounted. If the \fIfirst
|
||||
argument\fR is present, then shows only the tomb named that way or
|
||||
they were opened and the hooks that they mounted. If the first
|
||||
argument is present, then shows only the tomb named that way or
|
||||
returns an error if its not found.
|
||||
|
||||
.B
|
||||
.IP "index"
|
||||
Creates or updates the \fIsearch index\fR of a tomb, or all tombs currently
|
||||
opened if none is specified. Indexes are created using updatedb(8) and
|
||||
enable users to run quick search commands using simple word patterns.
|
||||
|
||||
.B
|
||||
.IP "search"
|
||||
Searches through all tombs currently open for filenames matching one
|
||||
or more text patterns given as arguments. Search returns a list of
|
||||
files found inside the tombs that have been previously indexed using
|
||||
locate(1). The option \fI--regex\fR can be used to interpret all
|
||||
patterns as extended regexps.
|
||||
|
||||
.B
|
||||
.IP "close"
|
||||
Closes a currently open tomb. If more tombs are open, the first
|
||||
|
74
src/tomb
74
src/tomb
@ -384,6 +384,9 @@ Commands:
|
||||
|
||||
open open an existing TOMB
|
||||
|
||||
index update the search indexes of tombs
|
||||
search looks for filenames matching text patterns
|
||||
|
||||
list list open TOMBs
|
||||
|
||||
close close a TOMB (or all)
|
||||
@ -1661,6 +1664,65 @@ resize_tomb() {
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
# {{{ - Index
|
||||
# index files in all tombs for search
|
||||
# $1 is optional, to specify a tomb
|
||||
index_tombs() {
|
||||
{ command -v updatedb > /dev/null } || {
|
||||
die "Cannot index tombs on this system: updatedb not installed" }
|
||||
|
||||
if [ $1 ]; then
|
||||
# list a specific tomb
|
||||
mounted_tombs=`mount -l |
|
||||
awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`
|
||||
else
|
||||
# list all open tombs
|
||||
mounted_tombs=`mount -l |
|
||||
awk '/^\/dev\/mapper\/tomb/ { print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`
|
||||
fi
|
||||
if ! [ $mounted_tombs ]; then
|
||||
if [ $1 ]; then
|
||||
die "There seems to be no open tomb engraved as [$1]"
|
||||
else
|
||||
die "I can't see any open tomb, may they all rest in peace."
|
||||
fi
|
||||
fi
|
||||
yes "Creating and updating search indexes"
|
||||
for t in ${(f)mounted_tombs}; do
|
||||
mapper=`basename ${t[(ws:;:)1]}`
|
||||
tombname=${t[(ws:;:)5]}
|
||||
tombmount=${t[(ws:;:)2]}
|
||||
say "Indexing $tombname"
|
||||
updatedb -l 0 -o ${tombmount}/.updatedb -U ${tombmount}
|
||||
say "search index updated"
|
||||
done
|
||||
}
|
||||
search_tombs() {
|
||||
{ command -v locate > /dev/null } || {
|
||||
die "Cannot index tombs on this system: updatedb not installed" }
|
||||
|
||||
# list all open tombs
|
||||
mounted_tombs=(`mount -l |
|
||||
awk '/^\/dev\/mapper\/tomb/ { print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`)
|
||||
{ test ${#mounted_tombs} = 0 } && {
|
||||
die "I can't see any open tomb, may they all rest in peace." }
|
||||
yes "Searching for: $fg_bold[white]${=PARAM}$fg_no_bold[white]"
|
||||
for t in ${(f)mounted_tombs}; do
|
||||
mapper=`basename ${t[(ws:;:)1]}`
|
||||
tombname=${t[(ws:;:)5]}
|
||||
tombmount=${t[(ws:;:)2]}
|
||||
{ test -r ${tombmount}/.updatedb } || {
|
||||
no "skipping tomb $tombname: not indexed"
|
||||
no "run 'tomb index' to create indexes"
|
||||
continue }
|
||||
say "Searching in tomb $tombname"
|
||||
locate -d ${tombmount}/.updatedb -e -i ${=PARAM}
|
||||
say "Matches found: `locate -d ${tombmount}/.updatedb -e -i -c ${=PARAM}`"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# {{{ - List
|
||||
# list all tombs mounted in a readable format
|
||||
# $1 is optional, to specify a tomb
|
||||
@ -1950,6 +2012,10 @@ main() {
|
||||
subcommands_opts[help]=""
|
||||
subcommands_opts[slam]=""
|
||||
subcommands_opts[list]="-get-mountpoint"
|
||||
|
||||
subcommands_opts[index]=""
|
||||
subcommands_opts[search]=""
|
||||
|
||||
subcommands_opts[help]=""
|
||||
subcommands_opts[bury]=""
|
||||
subcommands_opts[exhume]=""
|
||||
@ -2085,6 +2151,14 @@ main() {
|
||||
status)
|
||||
launch_status $PARAM[1]
|
||||
;;
|
||||
|
||||
index)
|
||||
index_tombs $PARAM[1]
|
||||
;;
|
||||
search)
|
||||
search_tombs ${=PARAM}
|
||||
;;
|
||||
|
||||
help)
|
||||
usage
|
||||
;;
|
||||
|
Loading…
x
Reference in New Issue
Block a user