Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: dnf5 completions



On 11/4/24 10:20 PM, Bart Schaefer wrote:
On Mon, Nov 4, 2024 at 4:34 PM Gamcheong YUEN <microsoft.zh.cn@xxxxxxxxx> wrote:

dnf5 has become the default package manager of Fedora 41, which is release last week. Please consider update the completion codes adapted to the new version.

There were a couple of messages about this back in July ("fedora 41
uses dnf5 and is no longer compatible ...") but nothing conclusive.
Anyone have time to look?

Added dnf5 to the #compdef line and fixed package completion for dnf5
haven't gone thru what options are new/removed.

diff --git a/Completion/Redhat/Command/_dnf b/Completion/Redhat/Command/_dnf
index a5edf8564..1470023e6 100644
--- a/Completion/Redhat/Command/_dnf
+++ b/Completion/Redhat/Command/_dnf
@@ -1,27 +1,11 @@
-#compdef dnf dnf-2 dnf-3
+#compdef dnf dnf5
 #
 # based on dnf-4.2.18
 #

 _dnf_helper() {
-  # Get the pathname of the python executable from the 1st line of dnf-2/dnf-3.
-  # Probably /usr/bin/python{2,3} or /usr/libexec/platform-python.
-  local shebang
-  read -u0 shebang < $(readlink -f /usr/bin/dnf)
-  local python_exec=${${shebang##\#! #}%% *}
-  local -a helper_script=(
-    'import sys'
-    'from dnf.cli.completion_helper import main'
-    'main(sys.argv[1:])'
-  )
-  $python_exec -c ${(j.;.)helper_script} "$@" "$PREFIX" \
-               -d 0 -q -C --assumeno --nogpgcheck 2>/dev/null </dev/null
-}
-
-_dnf_query_db() {
-  # $1: table name in the database ('available' or 'installed')
-  sqlite3 -batch -init /dev/null "$cache_file" \
-          "select pkg from $1 WHERE pkg LIKE '$PREFIX%$SUFFIX'"
+  _call_program commands dnf "${(q-)@}" "${(q-)PREFIX}\*" \
+    -q -C --assumeno --nogpgcheck 2>/dev/null </dev/null
 }

 _dnf_repositories() {
@@ -30,7 +14,7 @@ _dnf_repositories() {
   zparseopts -D -E - T:=selected
   selected=$selected[2]
   _wanted $selected-repositories expl "$selected repository" \
-          compadd "$@" - $(_dnf_helper repolist --$selected)
+    compadd "$@" - "${(@)${(f)$(_dnf_helper repolist --$selected)}[2,-1]%% *}"
 }

 _dnf_packages() {
@@ -38,19 +22,14 @@ _dnf_packages() {
   local selected pkgs expl
   zparseopts -D -E - T:=selected
   selected=$selected[2]
+  # outside of quickly finding uses of this function, i don't see the point of this
+  # if branch.
   if [[ $selected = upgradable ]]; then
-    pkgs=( $(_dnf_helper upgrade) )
-  elif [[ -r $cache_file ]]; then
-    local table=$selected
-    # 'available' table contains both 'available' and 'installed' packages
-    [[ $selected = all ]] && table=available
-    pkgs=( $(_dnf_query_db $table) )
-    if [[ $selected = available ]]; then
-      local inst=( $(_dnf_query_db installed) )
-      pkgs=( ${pkgs:|inst} )  # remove installed packages
-    fi
+    # the trailing space since due to fedora 41 >= --queryformat not adding an implicit \n
+    pkgs=( $(_dnf_helper repoquery --upgrades --queryformat='%{name} ') )
   else
-    pkgs=( $(_dnf_helper list --$selected) )
+    [[ $selected = all ]] && selected=available
+    pkgs=( $(_dnf_helper repoquery --$selected --queryformat='%{name} ') )
   fi
   _wanted $selected-packages expl "$selected package" compadd "$@" -a pkgs
 }
@@ -195,7 +174,6 @@ _dnf_repository_packages() {
 }

 _dnf() {
-  local cache_file="/var/cache/dnf/packages.db"
   local -a opts=(
     '(-6)-4[resolve to IPv4 addresses only]'
     '(-4)-6[resolve to IPv6 addresses only]'





Messages sorted by: Reverse Date, Date, Thread, Author