added pkgf

This commit is contained in:
fatalerrors
2026-06-02 16:36:20 +02:00
parent 4882bee0ad
commit 7c14c67ad0
3 changed files with 83 additions and 3 deletions

View File

@@ -86,7 +86,8 @@ help()
printf "mdcat\t\tRender Markdown files in terminal with colors and code frames\n"
printf "meteo\t\tDisplay weather forecast for the configured or given city\n"
printf "myextip\t\tGet information about your public IP address\n"
printf "pkgs\t\tSearch for a pattern in installed package names (dpkg/rpm, supports -i)\n"
printf "pkgf\t\tFind which installed package owns a given file (distro-aware)\n"
printf "pkgs\t\tSearch for a pattern in installed package names (distro-aware)\n"
printf "ppg\t\tLook for the given pattern in running processes\n"
printf "ppn\t\tList processes matching an exact command name\n"
printf "ppu\t\tList processes owned by a specific user\n"

View File

@@ -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