Skip to content

Commit

Permalink
Add exec
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Mar 18, 2022
1 parent bad15e4 commit 83cc11d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
36 changes: 36 additions & 0 deletions cmds/exec.js
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
37 changes: 37 additions & 0 deletions lisp/exec.el
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 83cc11d

Please sign in to comment.