void-linux / xbps

The X Binary Package System (XBPS)
https://voidlinux.org/xbps/
Other
822 stars 124 forks source link

search for alternatives providers with xbps-query? #499

Open classabbyamp opened 2 years ago

classabbyamp commented 2 years ago

xbps-query -Rp alternatives -s vi returns nothing currently (exits 2). perhaps it should search for all packages that provide the vi alternative set.

anddam commented 2 years ago

perhaps it should search for all packages that provide the vi alternative set.

Yeah, that would be handy.

Duncaen commented 2 years ago

The way the packages alternatives property is setup and how we print properties would require special handling for this case.

I added a repository mode to xbps-alternatives, which provides the same functionality and fits better imho https://github.com/void-linux/xbps/pull/340.

dmarto commented 2 years ago

Lurking around I found this issue, and I remembered I have a patch for that https://github.com/dmarto/xbps/commit/90d28910dc4bd49c147bc6106028192fc166ca13

My use case is the following script (that I use in combo with another one to find files that are not created/managed/owned by a package).

#!/bin/bash
# xalts [STRING]
#  alternatives search, prints results in xbps-query -o compatible way

while read alt; do
    [ -z "${alt}" ] && continue

    alt=${alt% (*)}

    pkg=${alt%%:*}

    real=${alt##*:}

    dir=$(dirname "$real")

    link=${alt#*: }
    link=${link%:*}
    [ "$(dirname "$link")" = "." ] && link="$dir/$link"

    echo "$pkg: $link -> $real (link)"

done <<< $(x xbps-query -R -p alternatives --search="$1")

If it is of intereset, I could open a PR.