Make run-command-recipe-scripts understand non-executable shebang scripts

This commit is contained in:
Jeremy Dormitzer 2022-05-05 14:41:14 -04:00
parent a2e0b17332
commit c021061dc5

View File

@ -332,6 +332,12 @@
(defvar run-command-recipe-scripts--script-dirs '("." "bin" "scripts"))
(defun get-script-run-command (file)
(with-temp-buffer
(insert-file-contents-literally file)
(when-let* ((line (s-trim (thing-at-point 'line t))))
(cadr (s-match (rx "#!" (group (1+ anychar))) line)))))
(defun run-command-recipe-scripts ()
(let* ((root-dir (expand-file-name (or (projectile-project-root) default-directory)))
(shell (or (getenv "SHELL") "/usr/bin/env bash"))
@ -339,12 +345,18 @@
(lambda (dir)
(let ((dir (f-join root-dir dir)))
(when (f-dir? dir)
(f-files dir #'file-executable-p))))
(f-files
dir
(lambda (file)
(or (file-executable-p file)
(get-script-run-command file)))))))
run-command-recipe-scripts--script-dirs)))
(-map
(lambda (file)
(list :command-name (f-relative file root-dir)
:command-line file
:command-line (if (file-executable-p file)
file
(format "%s %s" (get-script-run-command file) file))
:working-dir root-dir))
scripts)))