branch: master
commit ec3e062fb13d9fd4a922b180af3ae0218889d5ea
Author: Philip K <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel (counsel-file-jump): Use temp buffer instead of split-string
counsel (counsel-dired-jump): Use temp buffer instead of split-string
counsel (counsel-{file,dired}-jump): Avoid nbutlast
counsel (counsel-{file,dired}-jump): Factored out common code
Fixes #2120
---
counsel.el | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/counsel.el b/counsel.el
index b5b195d..f7da46f 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2549,7 +2549,19 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt
argument."
(message (cdr x)))
:caller 'counsel-rpm)))
-(defcustom counsel-file-jump-args ". -name '.git' -prune -o -type f -print |
cut -c 3-"
+(defun counsel--find-return-list (args skip-first)
+ (with-temp-buffer
+ (apply #'call-process find-program nil (current-buffer) nil args)
+ (goto-char (point-min))
+ (when skip-first
+ (forward-line))
+ (let ((start (point)) files)
+ (while (search-forward "\n" nil t)
+ (push (buffer-substring (+ 2 start) (1- (point))) files)
+ (setq start (point)))
+ files)))
+
+(defcustom counsel-file-jump-args ". -name .git -prune -o -type f -print"
"Arguments for the `find-command' when using `counsel-file-jump'."
:type 'string)
@@ -2567,10 +2579,7 @@ INITIAL-DIRECTORY, if non-nil, is used as the root
directory for search."
(counsel-require-program find-program)
(let ((default-directory (or initial-directory default-directory)))
(ivy-read "Find file: "
- (split-string
- (shell-command-to-string
- (concat find-program " " counsel-file-jump-args))
- "\n" t)
+ (counsel--find-return-list (split-string counsel-file-jump-args)
nil)
:matcher #'counsel--find-file-matcher
:initial-input initial-input
:action #'find-file
@@ -2586,7 +2595,7 @@ INITIAL-DIRECTORY, if non-nil, is used as the root
directory for search."
(dired (or (file-name-directory x) default-directory)))
"open in dired")))
-(defcustom counsel-dired-jump-args ". -name '.git' -prune -o -type d -print |
cut -c 3-"
+(defcustom counsel-dired-jump-args ". -name .git -prune -o -type d -print"
"Arguments for the `find-command' when using `counsel-dired-jump'."
:type 'string)
@@ -2604,10 +2613,7 @@ INITIAL-DIRECTORY, if non-nil, is used as the root
directory for search."
(counsel-require-program find-program)
(let ((default-directory (or initial-directory default-directory)))
(ivy-read "Find directory: "
- (split-string
- (shell-command-to-string
- (concat find-program " " counsel-dired-jump-args))
- "\n" t)
+ (counsel--find-return-list (split-string
counsel-dired-jump-args) t)
:matcher #'counsel--find-file-matcher
:initial-input initial-input
:action (lambda (d) (dired-jump nil (expand-file-name d)))