Skip to content

Commit 83cc11d

Browse files
committed
Add exec
1 parent bad15e4 commit 83cc11d

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

cmds/exec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (C) 2022 Jen-Chieh Shen
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with GNU Emacs; see the file COPYING. If not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301, USA.
18+
*/
19+
20+
"use strict";
21+
22+
const util = require("../src/util");
23+
24+
exports.command = 'exec [args..]';
25+
exports.desc = 'execute command with correct load-path set up';
26+
exports.builder = {
27+
args: {
28+
description: 'execution arguments',
29+
requiresArg: false,
30+
type: 'array',
31+
},
32+
};
33+
34+
exports.handler = async ({ args }) => {
35+
await util.e_call('exec', args);
36+
};

lisp/_prepare.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ other scripts internally. See function `eask-call'.")
9696
"Return non-nil if ARG is known internal command."
9797
(member arg eask--command-list))
9898

99-
(defun eask-argv (index) "Return argument value by INDEX." (elt index argv))
99+
(defun eask-argv (index) "Return argument value by INDEX." (elt argv index))
100100

101101
(defun eask-args ()
102102
"Get all arguments except options."

lisp/exec.el

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;;; exec.el --- Execute command with correct load-path set up -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Execute command with correct load-path set up
6+
;;
7+
;; $ eask exec [args..]
8+
;;
9+
;;
10+
;; Initialization options:
11+
;;
12+
;; [args..] execute command with correct load-path set up
13+
;;
14+
15+
;;; Code:
16+
17+
(load-file (expand-file-name
18+
"_prepare.el"
19+
(file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
20+
21+
(defun eask--add-bin-exec-path ()
22+
"Add all bin directory to `exec-path'."
23+
(dolist (filename (directory-files-recursively package-user-dir "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)"))
24+
(when (string-suffix-p "bin/" (file-name-directory filename))
25+
(add-to-list 'exec-path (file-name-directory filename))))
26+
(delete-dups exec-path))
27+
28+
(eask-start
29+
(eask-pkg-init)
30+
(eask--add-bin-exec-path)
31+
(setq commander-args (cdr argv))
32+
(if-let* ((command (eask-argv 0))
33+
(exe (executable-find command)))
34+
(load-file exe)
35+
(message "Executable `%s`.. not found" command)))
36+
37+
;;; exec.el ends here

0 commit comments

Comments
 (0)