diff options
-rw-r--r-- | lisp/find-script.el | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/find-script.el b/lisp/find-script.el new file mode 100644 index 0000000..9e3633a --- /dev/null +++ b/lisp/find-script.el | |||
@@ -0,0 +1,36 @@ | |||
1 | ;;; find-script.el --- Find a script in $PATH -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; This package makes it easier to find a script to edit in $PATH. The initial | ||
6 | ;; `rehash-exes' is slow, but it's stored in `*exes*' as a caching mechanism. | ||
7 | ;; However, I'm sure it could be improved. | ||
8 | |||
9 | ;; In addition, `*exes*' currently contains /all/ executables in $PATH, which | ||
10 | ;; ... maybe only the ones stored in some text format should be shown. | ||
11 | |||
12 | ;;; Code: | ||
13 | |||
14 | (defvar *exes* nil | ||
15 | "All the exectuables in $PATH. | ||
16 | Run `rehash-exes' to refresh this variable.") | ||
17 | |||
18 | (defun rehash-exes () | ||
19 | "List all the executables in $PATH. | ||
20 | Also sets `*exes*' parameter." | ||
21 | (setq *exes* | ||
22 | (cl-loop for dir in exec-path | ||
23 | append (file-expand-wildcards (concat dir "*")) | ||
24 | into exes | ||
25 | finally return exes))) | ||
26 | |||
27 | ;;;###autoload | ||
28 | (defun find-script (script) | ||
29 | "Find a file in $PATH." | ||
30 | (interactive | ||
31 | (list (let ((exes (or *exes* (rehash-exes)))) | ||
32 | (completing-read "Script> " exes nil t)))) | ||
33 | (find-file script)) | ||
34 | |||
35 | (provide 'find-script) | ||
36 | ;;; find-script.el ends here | ||