branch: externals/ivy-hydra
commit 7084d6031219fd015ab6f43b3557f0295786d44c
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>

    counsel.el (counsel-cd): Default to the directory of the current buffer
    
    Fixes #2340
---
 counsel.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/counsel.el b/counsel.el
index b34158a..6b7c290 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2936,12 +2936,13 @@ CALLER is passed to `ivy-read'."
   :grep-p t
   :exit-codes '(1 "No matches found"))
 
-(defun counsel-read-directory-name (prompt)
+(defun counsel-read-directory-name (prompt &optional default)
   "Read a directory name from user, a (partial) replacement of 
`read-directory-name'."
   (let ((counsel--find-file-predicate #'file-directory-p))
     (ivy-read prompt
               #'read-file-name-internal
               :matcher #'counsel--find-file-matcher
+              :def default
               :history 'file-name-history
               :keymap counsel-find-file-map
               :caller 'counsel-read-directory-name)))
@@ -2954,8 +2955,10 @@ CALLER is passed to `ivy-read'."
 Works for `counsel-git-grep', `counsel-ag', etc."
   (interactive)
   (counsel-delete-process)
-  (let ((input ivy-text)
-        (new-dir (counsel-read-directory-name "cd: ")))
+  (let* ((input ivy-text)
+         (def-dir (buffer-file-name (ivy-state-buffer ivy-last)))
+         (def-dir (and def-dir (file-name-directory def-dir)))
+         (new-dir (counsel-read-directory-name "cd: " def-dir)))
     (ivy-quit-and-run
       (funcall (ivy-state-caller ivy-last) input new-dir))))
 

Reply via email to