From 21d52953766f5ec82912fdf4fe4948fc637a354c Mon Sep 17 00:00:00 2001 From: Rahguzar Date: Sun, 22 Jun 2025 13:13:06 +0500 Subject: [PATCH] * lisp/pcmpl-rpm.el: Generate completions for dnf5 (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 | 50 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lisp/pcmpl-rpm.el b/lisp/pcmpl-rpm.el index d92e94a050e..239500c37dd 100644 --- a/lisp/pcmpl-rpm.el +++ b/lisp/pcmpl-rpm.el @@ -381,43 +381,41 @@ ;;; 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) -- 2.39.5