emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master b3ca5e3 119/348: Add counsel commands for jumping to files


From: Oleh Krehel
Subject: [elpa] master b3ca5e3 119/348: Add counsel commands for jumping to files
Date: Sat, 8 Apr 2017 11:03:39 -0400 (EDT)

branch: master
commit b3ca5e3a242a4300a84fdffa8364eb5aa754936d
Author: justbur <address@hidden>
Commit: justbur <address@hidden>

    Add counsel commands for jumping to files
    
    * counsel.el (counsel-file-jump): New command to jump to file in
      any sub directory
    * counsel.el (counsel-dired-jump): New command to jump to any sub
      directory
---
 counsel.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/counsel.el b/counsel.el
index 9a1344e..4210549 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1440,6 +1440,52 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
             :unwind #'counsel-delete-process
             :caller 'counsel-locate))
 
+;;** File Jump and Dired Jump
+
+;;;###autoload
+(defun counsel-file-jump (&optional initial-input initial-directory)
+  "Jump to a file from a list of all files directories
+below the current one.  INITIAL-INPUT can be given as the initial
+minibuffer input.  INITIAL-DIRECTORY, if non-nil, is used as the
+root directory for search."
+  (interactive
+   (list nil
+         (when current-prefix-arg
+           (read-directory-name "From directory: "))))
+  (let* ((default-directory (or initial-directory default-directory)))
+    (ivy-read "Find file: "
+              (split-string (shell-command-to-string "find * -type f"))
+              :matcher #'counsel--find-file-matcher
+              :initial-input initial-input
+              :action (lambda (x)
+                        (with-ivy-window
+                          (find-file (expand-file-name x ivy--directory))))
+              :preselect (when counsel-find-file-at-point
+                           (require 'ffap)
+                           (let ((f (ffap-guesser)))
+                             (when f (expand-file-name f))))
+              :require-match 'confirm-after-completion
+              :history 'file-name-history
+              :keymap counsel-find-file-map
+              :caller 'counsel-file-jump)))
+
+;;;###autoload
+(defun counsel-dired-jump (&optional initial-input initial-directory)
+  "Jump to a directory (in dired) from a list of all directories
+below the current one.  INITIAL-INPUT can be given as the initial
+minibuffer input.  INITIAL-DIRECTORY, if non-nil, is used as the
+root directory for search."
+  (interactive
+   (list nil
+         (when current-prefix-arg
+           (read-directory-name "From directory: "))))
+  (let* ((default-directory (or initial-directory default-directory)))
+    (ivy-read "Directory: "
+              (split-string (shell-command-to-string "find * -type d"))
+              :initial-input initial-input
+              :action #'dired-jump
+              :caller 'counsel-dired-jump)))
+
 ;;* Grep
 ;;** `counsel-ag'
 (defvar counsel-ag-map



reply via email to

[Prev in Thread] Current Thread [Next in Thread]