From fb11421906bb70b12626735bf2b78b79f0e1b634 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 24 Sep 2018 04:21:12 +0200 Subject: [PATCH] dnf: add more actions --- helm-system-packages-dnf.el | 55 ++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/helm-system-packages-dnf.el b/helm-system-packages-dnf.el index 0daf24d..a9293a5 100644 --- a/helm-system-packages-dnf.el +++ b/helm-system-packages-dnf.el @@ -1,4 +1,4 @@ -;;; helm-system-packages-dnf.el --- Helm UI for RPM-based distros using dnf. -*- lexical-binding: t -*- +;;; helm-system-packages-dnf.el --- Helm UI for RPM-based distros using DNF. -*- lexical-binding: t -*- ;; Copyright (C) 2018 Damien Cassou @@ -22,14 +22,21 @@ ;; along with this program. If not, see . ;;; Commentary: -;; Helm UI for RPM-based distributions using dnf. +;; Helm UI for RPM-based distributions using DNF. ;;; Code: (require 'helm-system-packages) +(require 'seq) + (defcustom helm-system-packages-dnf-actions - '(("Show package(s)" . helm-system-packages-dnf-info)) - "Actions for Helm guix." + (list + (cons "Show package(s)" #'helm-system-packages-dnf-info) + (cons "Install" #'helm-system-packages-dnf-install) + (cons "Uninstall" #'helm-system-packages-dnf-uninstall) + (cons "Browse homepage URL" #'helm-system-packages-dnf-browse-url) + (cons "Find files" #'helm-system-packages-dnf-find-files)) + "Actions for Helm DNF." :group 'helm-system-packages :type '(alist :key-type string :value-type function)) @@ -70,6 +77,46 @@ Otherwise display in `helm-system-packages-buffer'." (list candidate) (helm-marked-candidates))))))) +(defun helm-system-packages-dnf-install (_) + "Install marked candidates." + (helm-system-packages-run-as-root "dnf" "install")) + +(defun helm-system-packages-dnf-uninstall (_) + "Uninstall marked candidates." + (helm-system-packages-run-as-root "dnf" "remove")) + +(defun helm-system-packages-dnf-browse-url (_) + "Print homepage URLs of `helm-marked-candidates'. +With prefix argument, insert the output at point. +Otherwise display in `helm-system-packages-buffer'." + (helm-system-packages-browse-url + (save-match-data + (with-temp-buffer + (apply #'process-file "dnf" nil t nil "info" (helm-marked-candidates)) + (goto-char (point-min)) + (cl-loop + while (re-search-forward "^URL *: \\(.*\\)$" nil t) + collect (match-string-no-properties 1) into urls + finally return (seq-uniq urls #'string=)))))) + +(defun helm-system-packages-dnf--list-files (package) + "Return a list of all files installed by PACKAGE." + (message "Collecting files of %s" package) + (save-match-data + (with-temp-buffer + (process-file "dnf" nil t nil "repoquery" "-l" package) + (goto-char (point-min)) + (cl-loop + while (re-search-forward "^\\(/.*\\)$" nil t) + collect (match-string-no-properties 1))))) + +(defun helm-system-packages-dnf-find-files (_) + "Find files for marked candidates." + (let* ((package-files (make-hash-table :test #'equal))) + (dolist (package (helm-marked-candidates)) + (puthash package (helm-system-packages-dnf--list-files package) package-files)) + (helm-system-packages-find-files package-files))) + (defun helm-system-packages-dnf--delete-non-package-lines () "Remove every line of current package that is not a package." ;; delete summary line: