From 83cc11d5b9aa4f818a11f53cb29a6a076f05739b Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 19 Mar 2022 02:50:34 +0800 Subject: [PATCH] Add exec --- cmds/exec.js | 36 ++++++++++++++++++++++++++++++++++++ lisp/_prepare.el | 2 +- lisp/exec.el | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 cmds/exec.js create mode 100644 lisp/exec.el diff --git a/cmds/exec.js b/cmds/exec.js new file mode 100644 index 00000000..17612d1b --- /dev/null +++ b/cmds/exec.js @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2022 Jen-Chieh Shen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Emacs; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +"use strict"; + +const util = require("../src/util"); + +exports.command = 'exec [args..]'; +exports.desc = 'execute command with correct load-path set up'; +exports.builder = { + args: { + description: 'execution arguments', + requiresArg: false, + type: 'array', + }, +}; + +exports.handler = async ({ args }) => { + await util.e_call('exec', args); +}; diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 101bd2cd..d08131db 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -96,7 +96,7 @@ other scripts internally. See function `eask-call'.") "Return non-nil if ARG is known internal command." (member arg eask--command-list)) -(defun eask-argv (index) "Return argument value by INDEX." (elt index argv)) +(defun eask-argv (index) "Return argument value by INDEX." (elt argv index)) (defun eask-args () "Get all arguments except options." diff --git a/lisp/exec.el b/lisp/exec.el new file mode 100644 index 00000000..ddf06320 --- /dev/null +++ b/lisp/exec.el @@ -0,0 +1,37 @@ +;;; exec.el --- Execute command with correct load-path set up -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Execute command with correct load-path set up +;; +;; $ eask exec [args..] +;; +;; +;; Initialization options: +;; +;; [args..] execute command with correct load-path set up +;; + +;;; Code: + +(load-file (expand-file-name + "_prepare.el" + (file-name-directory (nth 1 (member "-scriptload" command-line-args))))) + +(defun eask--add-bin-exec-path () + "Add all bin directory to `exec-path'." + (dolist (filename (directory-files-recursively package-user-dir "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)")) + (when (string-suffix-p "bin/" (file-name-directory filename)) + (add-to-list 'exec-path (file-name-directory filename)))) + (delete-dups exec-path)) + +(eask-start + (eask-pkg-init) + (eask--add-bin-exec-path) + (setq commander-args (cdr argv)) + (if-let* ((command (eask-argv 0)) + (exe (executable-find command))) + (load-file exe) + (message "Executable `%s`.. not found" command))) + +;;; exec.el ends here