]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/pcmpl-rpm.el: Generate completions for dnf5
authorRahguzar <rahguzar@mailbox.org>
Sun, 22 Jun 2025 08:13:06 +0000 (13:13 +0500)
committerEshel Yaron <me@eshelyaron.com>
Wed, 23 Jul 2025 20:07:41 +0000 (22:07 +0200)
(pcmpl-rpm-dnf-cache-file): Remove now unused variable.
(pcmpl-rpm--dnf-packages): Use dnf repoquery.
(pcomplete/dnf): Adjust regexps to allow for help format of
dnf5.  New regexps works for both dnf4 and dnf5.  Add
aliases for better subcommand completion.  Better support
for dnf repoquery command.  (Bug#78661)

(cherry picked from commit 2e18b0bbe98d874739ad7dac461ae5e53349405f)

lisp/pcmpl-rpm.el

index d92e94a050ec735596d571860554c97475015887..239500c37dd18d38592dda396d070f46eb7573a0 100644 (file)
 
 ;;; DNF
 
-(defvar pcmpl-rpm-dnf-cache-file "/var/cache/dnf/packages.db"
-  "Location of the DNF cache.")
-
 (defun pcmpl-rpm--dnf-packages (status)
-  (when (and (file-exists-p pcmpl-rpm-dnf-cache-file)
-             (executable-find "sqlite3"))
-    (with-temp-message
-        "Getting list of packages..."
-      (process-lines "sqlite3" "-batch" "-init" "/dev/null"
-                     pcmpl-rpm-dnf-cache-file
-                     (pcase-exhaustive status
-                       ('available "select pkg from available")
-                       ('installed "select pkg from installed")
-                       ('not-installed "\
-select pkg from available where pkg not in (select pkg from installed)"))))))
+  "Return packages matching STATUS.
+STATUS should be one of --available or --installed."
+  (with-temp-message
+      "Getting list of packages..."
+    (process-lines "dnf" "--cacheonly" "repoquery" "--queryformat=%{name}\\n"
+                   status)))
 
 ;;;###autoload
 (defun pcomplete/dnf ()
   "Completion for the `dnf' command."
-  (let ((subcmds (pcomplete-from-help "dnf help"
-                                      :margin "^\\(\\)[a-z-]+  "
-                                      :argument "[a-z-]+")))
+  (let ((subcmds (pcomplete-from-help "dnf --help"
+                                      :margin (rx bol (group (* " "))
+                                                  (one-or-more (any "a-z" "-")) "  ")
+                                      :argument (rx (not "-") (1+ (any "a-z" "-"))))))
     (while (not (member (pcomplete-arg 1) subcmds))
       (pcomplete-here (completion-table-merge
                        subcmds
-                       (pcomplete-from-help "dnf help"))))
+                       (pcomplete-from-help "dnf --help"))))
     (let ((subcmd (pcomplete-arg 1)))
       (while (pcase subcmd
                ((guard (pcomplete-match "\\`-" 0))
-                (pcomplete-here
-                 (pcomplete-from-help `("dnf" "help" ,subcmd))))
-               ((or "downgrade" "reinstall" "remove")
-                (pcomplete-here (pcmpl-rpm--dnf-packages 'installed)))
-               ((or "install" "mark" "reinstall" "upgrade")
-                (pcomplete-here (pcmpl-rpm--dnf-packages 'not-installed)))
-               ((or "builddep" "changelog" "info" "list" "repoquery" "updateinfo")
-                (pcomplete-here (pcmpl-rpm--dnf-packages 'available))))))))
+                (if-let* (((pcomplete-match (rx bos "--what" (* (not "=")) "="
+                                                (group (* any)) eos)
+                                            0))
+                          (stub (pcomplete-match-string 1 0)))
+                    (pcomplete-here (pcmpl-rpm--dnf-packages "--available") stub)
+                  (pcomplete-here
+                   (pcomplete-from-help `("dnf" ,subcmd "--help")))))
+               ((or "downgrade" "dg" "upgrade" "up" "update" "reinstall" "rei"
+                    "remove" "rm")
+                (pcomplete-here (pcmpl-rpm--dnf-packages "--installed")))
+               ((or "builddep" "changelog" "info" "if" "install" "in" "list" "ls"
+                    "mark" "repoquery" "rq" "advisory" "updateinfo")
+                (pcomplete-here (pcmpl-rpm--dnf-packages "--available"))))))))
 
 (provide 'pcmpl-rpm)