branch: master commit ef78fb6dd0d89a51c2e3de7cf3610ff2a854e5df Author: CeleritasCelery <t.mac...@gmail.com> Commit: CeleritasCelery <t.mac...@gmail.com>
Add environment variable completion to counsel-find-file --- counsel.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/counsel.el b/counsel.el index fa214c4..557b531 100644 --- a/counsel.el +++ b/counsel.el @@ -1748,6 +1748,7 @@ currently checked out." (define-key map (kbd "C-DEL") 'counsel-up-directory) (define-key map (kbd "C-<backspace>") 'counsel-up-directory) (define-key map (kbd "C-M-y") 'counsel-yank-directory) + (define-key map "$" 'counsel-read-env) map)) (defun counsel-yank-directory () @@ -1892,6 +1893,32 @@ 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 (equal ivy-text "") + (let ((enable-recursive-minibuffers t) + (old-last ivy-last)) + (ivy-read "Env: " + (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)) + :action (lambda (x) + (ivy--reset-state (setq ivy-last old-last)) + (let ((path (cdr x))) + (when (file-accessible-directory-p path) + (setq path (file-name-as-directory path))) + (insert (abbreviate-file-name path))) + (ivy--cd-maybe)))) + (insert last-input-event))) + (defun counsel-find-file-action (x) "Find file X." (with-ivy-window