Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pkgfile #26

Open
papajoker opened this issue Sep 2, 2021 · 6 comments
Open

use pkgfile #26

papajoker opened this issue Sep 2, 2021 · 6 comments

Comments

@papajoker
Copy link

papajoker commented Sep 2, 2021

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

cmd="lsd -l"    # my test
if [ -f "/var/lib/pacman/sync/core.files" ]; then
    cmd=($cmd)
    echo "\"${cmd[0]}\" command not found"
    # pkgs=$(pacman -Fxq "usr/bin/.*/${cmd[0]}$")   # -Fx is slow ? 
    # find first command , after gui app
    found=$(pacman -Fl | grep -E "usr/bin/${cmd[0]}$|usr/share/applications/${cmd[0]}.desktop$" -m 1)
    if [ -n "$found" ]; then
        echo "\"${found% *}\" package to install for command \"/${found##* }\" ? [y/N]"
    fi
fi
@Chrysostomus
Copy link
Owner

When I tried implement this pamac originally, it ended being significantly slower than pkgfile. I'll check if the situation has changed...

@papajoker
Copy link
Author

papajoker commented Sep 2, 2021

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]

@yochananmarqos
Copy link
Contributor

yochananmarqos commented Sep 2, 2021

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): 

@papajoker
Copy link
Author

papajoker commented Sep 2, 2021

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

@papajoker
Copy link
Author

papajoker commented Sep 4, 2021

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)

@alexiswa
Copy link

alexiswa commented Dec 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants