;;; pcmpl-rc.el --- Completions For Emerge Command -*- lexical-binding: t; -*- ;; Copyright (C) 2024 Thanos Apollo ;; Author: Thanos Apollo ;; Keywords: pcomplete completions emerge gentoo ;; URL: https://git.thanosapollo.com/pcmpl-emerge ;; Version: 0.0.1 ;; Package-Requires: ((emacs "27.2")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Under development ;;; Code: (require 'cl-lib) (require 'pcomplete) (require 'subr-x) (defvar pcmpl-emerge-package-completions '() "Cache for emerge package completions.") (defvar pcmpl-emerge-options '("--sync" "--info" "--help" "-h" "--depclean" "-c" "--check-news" "--clean" "-av" "-avuDN" "--config" "--deselect" "-W" "--prune" "-P" "--regen" "--resume" "-r" "--searchdesc" "-S" "--unmerge" "-C" "--version" "-V" "--accept-properties=" "--accept-restrict=" "--alert" "-A" "--alphabetical" "--ask" "-a" "--autounmask-backtrack" "--autounmask" "--autounmask-only" "--autounmask-continue" "--autounmask-unrestricted-atoms" "--autounmask-keep-keywords" "--autounmask-keep-masks" "--autounmask-license" "--autounmask-use" "--autounmask-write" "--binpkg-changed-deps" "--binpkg-respect-use" "--buildpkg" "-b" "--buildpkg-exclude" "--buildpkgonly" "-B") "Emerge options.") (defun pcmpl-emerge-list-packages-in-repo (repo) "Return a list of package paths in REPO." (let (result) (setf result (split-string (shell-command-to-string (format "find %s -mindepth 2 -maxdepth 2 -type d -not -path '*/\.*'" repo)) "\n" t)) (setf result (mapcar (lambda (str) (string-remove-prefix (concat "/var/db/repos/" (file-name-nondirectory repo) "/") str)) result)) result)) (defun pcmpl-emerge-update-completions () "Update the completions cache." (let ((top-dir "/var/db/repos/") paths) (cl-loop for repo in (seq-filter (lambda (f) (not (string-match-p "\\.git$" f))) (directory-files top-dir t directory-files-no-dot-files-regexp)) do (setf paths (append paths (seq-filter (lambda (str) (not (string-match-p "/\\.git/" str))) (pcmpl-emerge-list-packages-in-repo repo))))) (setf pcmpl-emerge-package-completions (seq-uniq paths)))) ;;;###autoload (defun pcomplete/emerge () "Completion rules for the `emerge' command." (unless pcmpl-emerge-package-completions (pcmpl-emerge-update-completions)) (while (pcomplete-arg) (if (string-prefix-p "-" (pcomplete-arg)) (pcomplete-here* pcmpl-emerge-options) (pcomplete-here* pcmpl-emerge-package-completions)))) (provide 'pcmpl-emerge)