;;; 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
