From 46487b4a33e043cbeff8759b26e34ce067e96c75 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 6 May 2022 10:20:14 -0500 Subject: [PATCH] Add find-script.el --- lisp/find-script.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lisp/find-script.el 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 @@ +;;; 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