From c021061dc57e73d09d56c58e58b58db6b3879d43 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 5 May 2022 14:41:14 -0400 Subject: [PATCH] Make run-command-recipe-scripts understand non-executable shebang scripts --- emacs/.emacs.d/config/init-run-command.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/emacs/.emacs.d/config/init-run-command.el b/emacs/.emacs.d/config/init-run-command.el index 06e6653..a8b6b1d 100644 --- a/emacs/.emacs.d/config/init-run-command.el +++ b/emacs/.emacs.d/config/init-run-command.el @@ -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)))