Skip to content

Commit

Permalink
Merge pull request #55 from skissue/vterm
Browse files Browse the repository at this point in the history
Add support for executing recipes in vterm
  • Loading branch information
psibi authored Jul 1, 2024
2 parents bc7d009 + 58e8141 commit e74fef3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ h => help popup
? => help popup
g => refresh
e => execute recipe
E => execute recipe with eshell
E => execute recipe with a shell
w => execute recipe with arguments
W => open eshell without executing
W => open a shell without executing
#+end_example

* Customize
Expand All @@ -87,6 +87,7 @@ W => open eshell without executing
change the /justl-executable/ variable to set any explicit path.
- You can also control the width of the RECIPE column in the justl
buffer via /justl-recipe width/. By default it has a value of 20.
- You can change the shell between /eshell/ and /vterm/ using the /justl-shell/ variable. Using vterm requires [[https://github.com/akermu/emacs-libvterm][the vterm package]] to be installed.

* Future

Expand Down
65 changes: 59 additions & 6 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
;; ? => help popup
;; g => refresh
;; e => execute recipe
;; E => execute recipe with eshell
;; E => execute recipe with a shell
;; w => execute recipe with arguments
;; W => open eshell without executing
;; W => open a shell without executing
;;
;; Customize:
;;
Expand All @@ -63,6 +63,9 @@
;; You can also control the width of the RECIPE column in the justl
;; buffer via `justl-recipe width`. By default it has a value of 20.
;;
;; You can change the shell between `eshell' and `vterm' using the `justl-shell'
;; variable. Using vterm requires the `vterm' package to be installed.

Check warning on line 67 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

There should be two spaces after a period

Check warning on line 67 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

There should be two spaces after a period

Check warning on line 67 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

There should be two spaces after a period

Check warning on line 67 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

There should be two spaces after a period
;;

;;; Code:

Expand Down Expand Up @@ -114,6 +117,13 @@ other cases, it's a known path."
:type 'boolean
:safe 'booleanp)

(defcustom justl-shell 'eshell
"Shell to use when running recipes.
Can be either Eshell or vterm. Using vterm requires the vterm package to

Check warning on line 122 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

There should be two spaces after a period

Check warning on line 122 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

There should be two spaces after a period

Check warning on line 122 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

There should be two spaces after a period

Check warning on line 122 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

There should be two spaces after a period
be installed."
:type '(choice (const eshell)
(const vterm)))

(defun justl--recipe-output-buffer (recipe-name)
"Return the buffer name for the RECIPE-NAME."
(if justl-per-recipe-buffer
Expand Down Expand Up @@ -452,11 +462,11 @@ They are returned as objects, as per the JSON output of \"just --dump\"."
(let ((map (make-sparse-keymap)))
(define-key map (kbd "g") 'justl--refresh-buffer)
(define-key map (kbd "e") 'justl-exec-recipe)
(define-key map (kbd "E") 'justl-exec-eshell)
(define-key map (kbd "E") 'justl-exec-shell)
(define-key map (kbd "?") 'justl-help-popup)
(define-key map (kbd "h") 'justl-help-popup)
(define-key map (kbd "w") 'justl--exec-recipe-with-args)
(define-key map (kbd "W") 'justl-no-exec-eshell)
(define-key map (kbd "W") 'justl-no-exec-shell)
(define-key map (kbd "RET") 'justl-go-to-recipe)
map)
"Keymap for `justl-mode'.")
Expand Down Expand Up @@ -506,6 +516,49 @@ not executed."
(interactive)
(justl-exec-eshell t))

(defun justl-exec-vterm (&optional no-send)
"Execute just recipe in vterm.
When NO-SEND is non-nil, the command is inserted ready for editing but
is not executed."
(interactive)
(unless (require 'vterm nil t)
(user-error "Package `vterm' was not found!"))
(let* ((recipe (justl--get-recipe-under-cursor))

Check warning on line 526 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

Unused lexical variable ‘vterm-buffer-name’
(vterm-buffer-name (format "justl - vterm - %s" (justl--recipe-name recipe)))

Check warning on line 527 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

Unused lexical variable ‘vterm-buffer-name’

Check warning on line 527 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

Unused lexical variable ‘vterm-buffer-name’

Check warning on line 527 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

Unused lexical variable ‘vterm-buffer-name’
(default-directory (f-dirname justl-justfile)))
(vterm)

Check warning on line 529 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

the function ‘vterm’ is not known to be defined.

Check warning on line 529 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

the function ‘vterm’ is not known to be defined.

Check warning on line 529 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

the function ‘vterm’ is not known to be defined.

Check warning on line 529 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

the function ‘vterm’ is not known to be defined.

(let* ((recipe-name (justl--recipe-name recipe))
(recipe-args (justl--recipe-args recipe))
(transient-args (transient-args 'justl-help-popup))
(args-list (cons justl-executable
(append transient-args
(list recipe-name)
(mapcar 'justl--arg-default recipe-args)))))
(vterm-insert (string-join args-list " ")))

Check warning on line 538 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

the function ‘vterm-insert’ is not known to be defined.

Check warning on line 538 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

the function ‘vterm-insert’ is not known to be defined.

Check warning on line 538 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

the function ‘vterm-insert’ is not known to be defined.

Check warning on line 538 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

the function ‘vterm-insert’ is not known to be defined.
(unless no-send
(vterm-send-return))))

Check warning on line 540 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.3, false)

the function ‘vterm-send-return’ is not known to be defined.

Check warning on line 540 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.2, false)

the function ‘vterm-send-return’ is not known to be defined.

Check warning on line 540 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

the function ‘vterm-send-return’ is not known to be defined.

Check warning on line 540 in justl.el

View workflow job for this annotation

GitHub Actions / check (28.2, false)

the function ‘vterm-send-return’ is not known to be defined.

(defun justl-no-exec-vterm ()
"Open vterm with the recipe but do not execute it."
(interactive)
(justl-exec-vterm t))

(defun justl-exec-shell (&optional no-send)
"Execute just recipe in `justl-shell'.
When NO-SEND is non-nil, the command is inserted ready for editing but
is not executed."
(interactive)
(pcase justl-shell
('eshell (justl-exec-eshell no-send))
('vterm (justl-exec-vterm no-send))
(_ (user-error "Invalid value for `justl-shell'"))))

(defun justl-no-exec-shell ()
"Open `justl-shell' with the recipe but do not execute it."
(interactive)
(justl-exec-shell t))

(transient-define-argument justl--color ()
:description "Color output"
:class 'transient-switches
Expand All @@ -531,9 +584,9 @@ not executed."
;; global
("g" "Refresh" justl)
("e" "Exec" justl-exec-recipe)
("E" "Exec with eshell" justl-exec-eshell)
("E" "Exec with shell" justl-exec-shell)
("w" "Exec with args" justl--exec-recipe-with-args)
("W" "Open eshell with args" justl-no-exec-eshell)
("W" "Open shell with args" justl-no-exec-shell)
("RET" "Go to recipe" justl-go-to-recipe)
]
])
Expand Down

0 comments on commit e74fef3

Please sign in to comment.