summaryrefslogtreecommitdiff
path: root/pcmpl-emerge.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-02-16 09:12:13 +0200
committerThanos Apollo <[email protected]>2024-02-16 09:58:52 +0200
commit360e1a2b7c5f35894ef34114db8203772b07b89e (patch)
tree4e4f96180992964a65988fcf1fb42df876191ea6 /pcmpl-emerge.el
init project
Diffstat (limited to 'pcmpl-emerge.el')
-rw-r--r--pcmpl-emerge.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/pcmpl-emerge.el b/pcmpl-emerge.el
new file mode 100644
index 0000000..8c614a1
--- /dev/null
+++ b/pcmpl-emerge.el
@@ -0,0 +1,50 @@
+
+(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"))
+
+
+(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))
+ (pcomplete-here* pcmpl-emerge-options)
+ (pcomplete-here* pcmpl-emerge-package-completions))
+
+(provide 'pcmpl-emerge)
+