added pkgf
This commit is contained in:
@@ -194,6 +194,84 @@ export -f pkgs
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Find which installed package a file belongs to.
|
||||
# Usage: pkgf <file>
|
||||
pkgf()
|
||||
{
|
||||
local PARSED
|
||||
PARSED=$(getopt -o h --long help -n 'pkgf' -- "$@")
|
||||
# shellcheck disable=SC2181
|
||||
if [[ $? -ne 0 ]]; then
|
||||
disp E "Invalid options, use \"pkgf --help\" to display usage."
|
||||
return 1
|
||||
fi
|
||||
eval set -- "$PARSED"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
printf "pkgf: Find which installed package owns a given file.\n\n"
|
||||
printf "Usage: pkgf [options] <file>\n\n"
|
||||
printf "Options:\n"
|
||||
printf "\t-h, --help\tDisplay this help screen\n"
|
||||
return 0
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
disp E "Invalid option: $1"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
local file="$1"
|
||||
[[ -z "$file" ]] && {
|
||||
disp E "Please specify a file path."
|
||||
return 1
|
||||
}
|
||||
|
||||
local pkgmgr
|
||||
pkgmgr=$(get_pkgmgr) || {
|
||||
disp E "No usable package manager could be detected on this system."
|
||||
return 2
|
||||
}
|
||||
|
||||
case "$pkgmgr" in
|
||||
apt)
|
||||
dpkg -S "$file"
|
||||
;;
|
||||
dnf|yum|zypper)
|
||||
rpm -qf "$file"
|
||||
;;
|
||||
pacman)
|
||||
pacman -Qo "$file"
|
||||
;;
|
||||
apk)
|
||||
apk info --who-owns "$file"
|
||||
;;
|
||||
portage)
|
||||
qfile "$file"
|
||||
;;
|
||||
xbps)
|
||||
xbps-query -o "$file"
|
||||
;;
|
||||
nix)
|
||||
nix-locate "$file"
|
||||
;;
|
||||
*)
|
||||
disp E "Package manager '$pkgmgr' is not supported by pkgf."
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
export -f pkgf
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
load_conf "packages"
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user