pac-file: An ArchLinux Version of Debian's apt-file
Ever since I began using ArchLinux, I have wanted a utility similar to debian's apt-file that allows you to discover which package provides a particular file. Arch's package manager, pacman, has always allowed you to do this for a file you already have installed, via pacman -Qo /path/to/file but this doesn't help if the file isn't already present on your system.
Recently, ArchLinux's developers have decided to provide filelists containing the contents of each package in a repository on the repo mirrors (see discussion). I've written a utility pac-file that downloads and uncompresses the filelists for each repository enabled in /etc/pacman.conf and allows regex searching of them. This allows the user to discover which package contains a file, even if that package is not installed on the user's system.
pac-file is loosely based on a similar script developed by Abhishek Dasgupta and available on the arch-general mailing list.
Example
Suppose you are compiling a program and get an error about a missing library libImath.so To know which package to install to provide this dependency you could:
$ pac-file libImath.so
extra/openexr-1.4.0a-2 usr/lib/libImath.so.4
extra/openexr-1.4.0a-2 usr/lib/libImath.so.4.0.0
extra/openexr-1.4.0a-2 usr/lib/libImath.so
The output indicates that you should install openexr from the extra repo. pac-file searches via grep's extended regex engine, so searches like lib[Ii]math.so or lib*math work as expected.
Usage
pac-file is designed to be similar to pacman. You must first syncronize (via -S or --sync) the filelists. This must be done as root because the filelists are stored in /var/lib/pacman/filelists (although this can be changed in the script). See pac-file -h for more information.
Download
You can download pac-file here. It is also available from the archlinux.fr repo. Let me know if you like it or run into any bugs.