diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2014-10-10 16:40:30 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2014-10-10 16:44:54 +0200 |
commit | 49110cec34d65b2d8cf3433aa3b881111197dd3c (patch) | |
tree | cf0a0c22b85a1e9dcb7e226ce4fbdb0b03a39500 | |
parent | 8c7dc218f1fb73d00c25b0b802e75af12369086d (diff) | |
download | xtools-49110cec34d65b2d8cf3433aa3b881111197dd3c.tar.gz xtools-49110cec34d65b2d8cf3433aa3b881111197dd3c.tar.xz xtools-49110cec34d65b2d8cf3433aa3b881111197dd3c.zip |
xlocate: use locatedb ~/.cache/xlocate.db if it exists
-rwxr-xr-x | xlocate | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/xlocate b/xlocate index 705cd34..0b34fe0 100755 --- a/xlocate +++ b/xlocate @@ -1,4 +1,24 @@ #!/bin/sh # xlocate PATTERN - locate files in all XBPS packages -xbps-query --regex -Ro "$@" | sed 's/ *([^)]*)$//; s/^\([^ ]*\)-[^-]*: /\1\t/' +: ${XLOCATE_DB:=~/.cache/xlocate.db} + +if [ -e "$XLOCATE_DB" ]; then + if [ "$XLOCATE_DB" -ot /var/db/xbps/http___repo_voidlinux_eu_current/*-repodata ] || [ ! -s "$XLOCATE_DB" ]; then + echo "xlocate: reindexing database..." 1>&2 + xbps-query --regex -Ro '' | + sed 's/ *([^)]*)$//; s|: ||;' | + /usr/libexec/frcode >"$XLOCATE_DB" + fi + rx= + case "$1" in + # Just . is unlikely to be a regex here... + *[*+\\\[\]]*) rx=-r;; + esac + # XXX also matches template in package name. + locate $rx -d "$XLOCATE_DB" "$1" | + sed 's|^\([^/]*\)-[^-/]*/|\1\t/|' +else + xbps-query --regex -Ro "$@" | + sed 's/ *([^)]*)$//; s/^\([^ ]*\)-[^-]*: /\1\t/' +fi |