about summary refs log tree commit diff
path: root/xlocate
blob: 0b34fe0c1c58dfcbacc7393c5605935fde421e4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# xlocate PATTERN - locate files in all XBPS packages

: ${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