[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pcmpl-args ec71fe5813 28/33: Reimplemented pass find in e-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pcmpl-args ec71fe5813 28/33: Reimplemented pass find in e-lisp |
Date: |
Mon, 31 Jan 2022 11:59:28 -0500 (EST) |
branch: elpa/pcmpl-args
commit ec71fe58134d612a7324a21e31930689d7de9eee
Author: Valeriy Litkovskyy <vlr.ltkvsk@protonmail.com>
Commit: Troy Hinckley <t.macman@gmail.com>
Reimplemented pass find in e-lisp
---
pcmpl-args.el | 60 +++++++++++++++++++++++++++++++----------------------------
1 file changed, 32 insertions(+), 28 deletions(-)
diff --git a/pcmpl-args.el b/pcmpl-args.el
index 373ec17eee..e42dffe147 100644
--- a/pcmpl-args.el
+++ b/pcmpl-args.el
@@ -3449,32 +3449,36 @@ It is suffixed with a slash."
(expand-file-name "~/.password-store"))))
(concat directory "/")))
-(defun pcmpl-args-pass-find (&rest find-args)
+(defun pcmpl-args-pass-find (&optional type)
"Return a list of password-store entries.
By default, return all directories and files in password-store.
-These can be limited by `FIND-ARGS'.
-
-`FIND-ARGS' is a list of find (GNU/findutils) arguments. For
-example, to get only directories:
-
-\(pcmpl-args-pass-find \"-type\" \"d\")"
- (let* ((prefix (pcmpl-args-pass-prefix))
- (args `("find" "-L" ,prefix
- "(" "-name" ".git*" "-o" "-name" ".gpg-id" ")" "-prune"
- "-o" ,@find-args "-print"))
- (rx (concat "^" (regexp-quote prefix) "\\(.+?\\)\\(?:\\.gpg\\)?$")))
- (with-temp-buffer
- (apply #'pcmpl-args-process-file args)
- (goto-char (point-min))
- (save-match-data
- (while (search-forward-regexp rx nil t)
- (replace-match "\\1")))
- (beginning-of-line)
- (let (lines)
- (while (progn (push (string-trim-right (thing-at-point 'line t)) lines)
- (forward-line -1)
- (not (bobp))))
- lines))))
+These can be limited by TYPE.
+
+If TYPE is :files, return only files. If TYPE is :directories,
+return only directories."
+ (let ((dir (pcmpl-args-pass-prefix)))
+
+ (cl-labels
+ ((no-git (dir) (not (string-suffix-p "/.git" dir)))
+ (chop-dir (entry) (string-remove-prefix dir entry))
+ (chop-ext (entry) (string-remove-suffix ".gpg" entry))
+ (chop (entry) (chop-dir (chop-ext entry)))
+ (dotp (file) (string-prefix-p "." (file-name-base file)))
+ (gpgp (file) (string-suffix-p ".gpg" file))
+ (dot-or-gpg-p (file) (or (dotp file) (gpgp file))))
+
+ (cl-case type
+ (:files
+ (thread-last (directory-files-recursively dir "\\.gpg\\'" nil
#'no-git t)
+ (mapcar #'chop)))
+ (:directories
+ (thread-last (directory-files-recursively dir ".*" t #'no-git t)
+ (cl-delete-if #'dot-or-gpg-p)
+ (mapcar #'chop-dir)))
+ (t
+ (thread-last (directory-files-recursively dir ".*" t #'no-git t)
+ (cl-delete-if #'dotp)
+ (mapcar #'chop)))))))
(defun pcmpl-args-pass-keys (args)
"Return a list of gpg secret keys.
@@ -3500,7 +3504,7 @@ entered, it will be removed from returned list."
"Return specs for pass `SUBCOMMAND'."
(pcase subcommand
("edit"
- '((argument 0 (("PASSNAME" (:eval (pcmpl-args-pass-find "-type" "f")))))))
+ '((argument 0 (("PASSNAME" (:eval (pcmpl-args-pass-find :files)))))))
("find"
'((argument * (("PATTERN" none)))))
@@ -3521,7 +3525,7 @@ entered, it will be removed from returned list."
(pcmpl-args-command-subparser args specs seen)))))
("init"
- '((option "-p, --path=SUBFOLDER" (("SUBFOLDER" (:eval
(pcmpl-args-pass-find "-type" "d"))))
+ '((option "-p, --path=SUBFOLDER" (("SUBFOLDER" (:eval
(pcmpl-args-pass-find :directories))))
:help "GPGIDs are assigned for that specific SUBFOLDER of the
store")
(argument * (("GPGID" (:lambda pcmpl-args-pass-keys))))))
@@ -3532,7 +3536,7 @@ entered, it will be removed from returned list."
(argument 0 (("PASSNAME" (:eval (pcmpl-args-pass-find)))))))
("ls"
- '((argument 0 (("SUBFOLDER" (:eval (pcmpl-args-pass-find "-type"
"d")))))))
+ '((argument 0 (("SUBFOLDER" (:eval (pcmpl-args-pass-find
:directories)))))))
("rm"
'((option "-r, --recursive" :help "Delete PASSNAME recursively if it is a
directory")
@@ -3544,7 +3548,7 @@ entered, it will be removed from returned list."
:help "Copy the first (or specified) line to the clipboard")
(option "-q[LINENUMBER], --qrcode[=LINENUMBER]" (("LINENUMBER" none))
:help "Display a QR code of the first (or specified) line")
- (argument 0 (("PASSNAME" (:eval (pcmpl-args-pass-find "-type" "f")))))))
+ (argument 0 (("PASSNAME" (:eval (pcmpl-args-pass-find :files)))))))
((or "cp" "mv")
'((option "-f, --force" :help "Silently overwrite NEWPATH if it exists")
- [nongnu] elpa/pcmpl-args 83f43d0f6f 12/33: Reformat README, (continued)
- [nongnu] elpa/pcmpl-args 83f43d0f6f 12/33: Reformat README, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args e6957896b0 15/33: Add shell-quote-argument to name, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args a04b9f0308 14/33: Filter out backspace character in default man function output, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 6d45d2d7c1 16/33: Fixed too many subcommmands for git completions, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 02ae18bda3 33/33: Revert "Fix expansion of $PREFIX in most commands", ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 0b4d9bb8ce 25/33: Implemented col -b in elisp, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 4c299e8f64 27/33: Added missing subr-x dependency and bumped emacs version, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 5f2943fd70 30/33: Bump version after moving minimum Emacs to 25.1, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args 593811a570 29/33: Reimplemented listing of gpg keys in e-lisp, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args d911fddfa2 26/33: Fixed formatting and tabs, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args ec71fe5813 28/33: Reimplemented pass find in e-lisp,
ELPA Syncer <=
- [nongnu] elpa/pcmpl-args 604ea27bdf 17/33: Use cl-lib instead of cl, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args c162469e41 18/33: Minor fixes, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args e51aae79a7 32/33: Fix expansion of $PREFIX in most commands, ELPA Syncer, 2022/01/31
- [nongnu] elpa/pcmpl-args c812b254ba 23/33: Fixed docstrings, ELPA Syncer, 2022/01/31