diff options
| -rw-r--r-- | lisp/quality-of-life.el | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lisp/quality-of-life.el b/lisp/quality-of-life.el index 09bba46..8514f55 100644 --- a/lisp/quality-of-life.el +++ b/lisp/quality-of-life.el @@ -31,7 +31,34 @@ ;; If I'm typing a file name with capitalized letters, I may be holding shift ;; when I press space. This is a pain in the ass, and I don't use the feature ;; anyway, so I unbind it. - (bind-key "S-SPC" nil ivy-minibuffer-map)) + (bind-key "S-SPC" nil ivy-minibuffer-map) + + :config/el-patch + (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 (or + ;; Don't `file-exists-p' on TRAMP stuff + (el-patch-add (string-suffix-p ":/" val)) + (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)))) ;; `counsel' is a nice Ivy-based frontend for a couple of interactive commands. |