Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel (counsel-{file,dired}-jump): use temporary buffers as compared to split-string #2120

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions counsel.el
Expand Up @@ -2508,7 +2508,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)

Expand All @@ -2526,10 +2538,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
Expand All @@ -2545,7 +2554,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)

Expand All @@ -2563,10 +2572,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)))
Expand Down