branch: master
commit bedeb02e62a93c3a23814645a1cd705f5377fd74
Author: CeleritasCelery <[email protected]>
Commit: Oleh Krehel <[email protected]>
Move counsel-read-env to ivy mode
reading environment variables should be present in all read-file-name
functions, not just counsel-find-file
Fixes #1937
---
counsel.el | 26 --------------------------
ivy.el | 24 ++++++++++++++++++++++++
2 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/counsel.el b/counsel.el
index 1b4133c..b07ad91 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1892,32 +1892,6 @@ Skip some dotfiles unless `ivy-text' requires them."
(defvar counsel-find-file-speedup-remote t
"Speed up opening remote files by disabling `find-file-hook' for them.")
-(defun counsel-read-env ()
- "Read a file path environment variable and insert it into the
-minibuffer."
- (interactive)
- (if (and ivy--directory
- (equal ivy-text ""))
- (let* ((cands (cl-loop for pair in process-environment
- for (var val) = (split-string pair "=" t)
- if (and val (not (equal "" val)))
- if (file-exists-p
- (if (file-name-absolute-p val)
- val
- (setq val
- (expand-file-name val ivy--directory))))
- collect (cons var val)))
- (enable-recursive-minibuffers t)
- (x (ivy-read "Env: " cands))
- (path (cdr (assoc x cands))))
- (insert (if (file-accessible-directory-p path)
- (file-name-as-directory path)
- path))
- (ivy--cd-maybe))
- (insert last-input-event)))
-
-(define-key ivy-minibuffer-map "$" 'counsel-read-env)
-
(defun counsel-find-file-action (x)
"Find file X."
(with-ivy-window
diff --git a/ivy.el b/ivy.el
index e49764c..8f5acd2 100644
--- a/ivy.el
+++ b/ivy.el
@@ -412,6 +412,7 @@ action functions.")
(define-key map (kbd "C-c C-a") 'ivy-toggle-ignore)
(define-key map (kbd "C-c C-s") 'ivy-rotate-sort)
(define-key map [remap describe-mode] 'ivy-help)
+ (define-key map "$" 'ivy-magic-read-file-env)
map)
"Keymap used in the minibuffer.")
(autoload 'hydra-ivy/body "ivy-hydra" "" t)
@@ -2828,6 +2829,29 @@ Possible choices are
'ivy-magic-slash-non-match-cd-selected,
magic)
(ivy--create-and-cd canonical))))))
+(defun ivy-magic-read-file-env ()
+ "If reading filename, jump to environment variable location."
+ (interactive)
+ (if (and ivy--directory
+ (equal ivy-text ""))
+ (let* ((cands (cl-loop for pair in process-environment
+ for (var val) = (split-string pair "=" t)
+ if (and val (not (equal "" val)))
+ if (file-exists-p
+ (if (file-name-absolute-p val)
+ val
+ (setq val
+ (expand-file-name val
ivy--directory))))
+ collect (cons var val)))
+ (enable-recursive-minibuffers t)
+ (x (ivy-read "Env: " cands))
+ (path (cdr (assoc x cands))))
+ (insert (if (file-accessible-directory-p path)
+ (file-name-as-directory path)
+ path))
+ (ivy--cd-maybe))
+ (insert last-input-event)))
+
(defcustom ivy-magic-tilde t
"When non-nil, ~ will move home when selecting files.
Otherwise, ~/ will move home."