summary refs log tree commit diff stats
path: root/lisp/find-script.el
blob: 9e3633a1f272fd275907e84b7c2d25520819c346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;;; find-script.el --- Find a script in $PATH -*- lexical-binding: t; -*-

;;; Commentary:

;; This package makes it easier to find a script to edit in $PATH.  The initial
;; `rehash-exes' is slow, but it's stored in `*exes*' as a caching mechanism.
;; However, I'm sure it could be improved.

;; In addition, `*exes*' currently contains /all/ executables in $PATH, which
;; ... maybe only the ones stored in some text format should be shown.

;;; Code:

(defvar *exes* nil
  "All the exectuables in $PATH.
Run `rehash-exes' to refresh this variable.")

(defun rehash-exes ()
  "List all the executables in $PATH.
Also sets `*exes*' parameter."
  (setq *exes*
        (cl-loop for dir in exec-path
                 append (file-expand-wildcards (concat dir "*"))
                 into exes
                 finally return exes)))

;;;###autoload
(defun find-script (script)
  "Find a file in $PATH."
  (interactive
   (list (let ((exes (or *exes* (rehash-exes))))
           (completing-read "Script> " exes nil t))))
  (find-file script))

(provide 'find-script)
;;; find-script.el ends here