Difference between revisions of "Pkgfile"

From ArchWiki
Jump to navigation Jump to search
(Undo revision 341671 by Agent0 (talk) Not related to pkgfile, moved the info to [bash] article.)
(Command not found: Added Fish function, and changed formatting slightly.)
Line 45: Line 45:
 
To enable it in all children shells, you need to source the hook from one of your shell initialization files.
 
To enable it in all children shells, you need to source the hook from one of your shell initialization files.
  
* Example for [[Bash]]:
+
=== [[Bash]] ===
  
 
{{hc|~/.bashrc|
 
{{hc|~/.bashrc|
 
source /usr/share/doc/pkgfile/command-not-found.bash}}
 
source /usr/share/doc/pkgfile/command-not-found.bash}}
  
* Example for [[Zsh]]:
+
===  [[Zsh]] ===
  
 
{{hc|~/.zshrc|
 
{{hc|~/.zshrc|
 
source /usr/share/doc/pkgfile/command-not-found.zsh}}
 
source /usr/share/doc/pkgfile/command-not-found.zsh}}
 +
 +
=== [[Fish]] ===
 +
 +
{{ic|pkgfile}} does not provide a hook specifically for Fish, but it is sufficient to define your own {{ic|command-not-found}} function, which will be run when Fish encounters and unknown command.
 +
 +
{{hc|~/.config/fish/functions/command-not-found.fish|
 +
function command-not-found
 +
        set cmd $argv[2]
 +
        set pkgs (pkgfile -b -v $argv 2>/dev/null)
 +
        if test -n $pkgs
 +
                echo "$cmd may be found in the following packages:"
 +
                echo "$pkgs"
 +
                return 0
 +
        end
 +
        return 127
 +
end}}

Revision as of 13:54, 27 October 2014

zh-CN:Pkgfile pkgfile is a tool for searching files from packages in the official repositories.

Installation

Install pkgfile from the official repositories, or pkgfile-gitAUR from the AUR.

The pkgfile database can then be synced with:

# pkgfile -u

Usage

To search for a package that owns the file makepkg:

$ pkgfile makepkg
core/pacman

To list all files provided by archlinux-keyring:

$ pkgfile -l archlinux-keyring
core/archlinux-keyring usr/
core/archlinux-keyring usr/share/
core/archlinux-keyring usr/share/pacman/
core/archlinux-keyring usr/share/pacman/keyrings/
core/archlinux-keyring usr/share/pacman/keyrings/archlinux-revoked
core/archlinux-keyring usr/share/pacman/keyrings/archlinux-trusted
core/archlinux-keyring usr/share/pacman/keyrings/archlinux.gpg

Command not found

pkgfile includes a "command not found" hook that will automatically search the official repositories, when entering an unrecognized command:

$ abiword
abiword may be found in the following packages:
  extra/abiword 2.8.6-7	usr/bin/abiword

To enable it in all children shells, you need to source the hook from one of your shell initialization files.

Bash

~/.bashrc
source /usr/share/doc/pkgfile/command-not-found.bash

Zsh

~/.zshrc
source /usr/share/doc/pkgfile/command-not-found.zsh

Fish

pkgfile does not provide a hook specifically for Fish, but it is sufficient to define your own command-not-found function, which will be run when Fish encounters and unknown command.

~/.config/fish/functions/command-not-found.fish
function command-not-found
        set cmd $argv[2]
        set pkgs (pkgfile -b -v $argv 2>/dev/null)
        if test -n $pkgs
                echo "$cmd may be found in the following packages:"
                echo "$pkgs"
                return 0
        end
        return 127
end