Open papajoker opened 3 years ago
When I tried implement this pamac originally, it ended being significantly slower than pkgfile. I'll check if the situation has changed...
here, i use grep -m1 so, if found , this command not search in all database
other way (for me best speed) is to read in ".files", example (search only in /usr/bin lower case command)
#!/usr/bin/env bash
# command-not-found
cmd="$@"
for repo in $(pacman-conf -l); do
echo "find in $repo ..."
pkgs=$(zcat "/var/lib/pacman/sync/${repo}.files"|awk '/%NAME%/ {getline;name=$0} /usr\/bin\/'"${1,,}"'$/ {printf "%s %s\n",name,$1}')
if [ -n "$pkgs" ]; then
printf "package: %s command: /%s exists, install it ? [y/N]\n" ${pkgs[@]}
exit 0 # not search in other
fi
exit 127 # not found :(
done
result
./test.sh vlc -x
find in core ...
find in extra ...
package: vlc command: /usr/bin/vlc
./test.sh zstd xx
find in core ...
package: zstd command: /usr/bin/zstd
EDIT: as @yochananmarqos package, display more info (url)
pkgs=$(zcat "/var/lib/pacman/sync/${repo}.files"|awk '/^%NAME%$/ {getline;name=$0} /^%URL%$/ {getline;url=$0} /usr\/bin\/'"${1,,}"'$/ {printf "%s %s %s\n",name,$1,url}')
...
printf "package: %s command: /%s exists, %s, install it ? [y/N]\n" ${pkgs[@]}
result:
./test.sh Firefox
find in core ...
find in extra ...
package: firefox command: /usr/bin/firefox exists, https://www.mozilla.org/firefox/, install it ? [y/N]
There's also command-not-found which uses the existing Pacman database. However, it's not in active development. Neat thing is, it has some options pkgfile does not:
❯ yarn
find-the-command: "yarn" is not found locally, searching in repositories...
"yarn" may be found in package "community/yarn"
What would you like to do?
1) install 2) info 3) list files 4) list files (paged)
Action (0 to abort):
yes good, but only not use pacman sync datatase ? and us we have .files with pamac my first idea is to re-use pamac database
gist created for test speed 4 solutions, zsh code
results at file end : best is pacman -Fl and grep
ps: pamac : always read all, so always same time (if result in core or community change nothing)
i know this hasnt been posted on for a long time, but this has been troubling many users for quite some time. Not sure if there are any alternatives.
why use pkgfile ? with pamac we have *.files so this package is not usefull
test code (write in bash NOT zsh !!!!!) for command-not-found