mirror of
https://github.com/SqrtMinusOne/eshell-atuin.git
synced 2025-12-11 04:43:02 +03:00
eshell-atuin: use with-environment-variables for ATUIN_SESSION (#4)
This commit is contained in:
parent
a7ec9718b2
commit
24ac9fac36
1 changed files with 24 additions and 15 deletions
|
|
@ -125,6 +125,9 @@ include here. Some examples:
|
||||||
(defvar-local eshell-atuin--last-command-start nil
|
(defvar-local eshell-atuin--last-command-start nil
|
||||||
"Start time the of current eshell command.")
|
"Start time the of current eshell command.")
|
||||||
|
|
||||||
|
(defvar eshell-atuin--session-id nil
|
||||||
|
"Current atuin session ID.")
|
||||||
|
|
||||||
(defun eshell-atuin--get-input ()
|
(defun eshell-atuin--get-input ()
|
||||||
"Get eshell input string on the current line."
|
"Get eshell input string on the current line."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
|
@ -142,13 +145,14 @@ results of the command in `eshell-atuin--post-exec'."
|
||||||
(when-let ((input (eshell-atuin--get-input)))
|
(when-let ((input (eshell-atuin--get-input)))
|
||||||
(setq eshell-atuin--history-id
|
(setq eshell-atuin--history-id
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(let ((ret (call-process
|
(with-environment-variables (("ATUIN_SESSION" eshell-atuin--session-id))
|
||||||
eshell-atuin-executable nil t nil
|
(let ((ret (call-process
|
||||||
"history" "start" "--" input)))
|
eshell-atuin-executable nil t nil
|
||||||
(unless (= 0 ret)
|
"history" "start" "--" input)))
|
||||||
(error "`atuin history start' retured %s: %s" ret (buffer-string)))
|
(unless (= 0 ret)
|
||||||
(buffer-substring-no-properties
|
(error "`atuin history start' retured %s: %s" ret (buffer-string)))
|
||||||
(point-min) (point-max)))))
|
(buffer-substring-no-properties
|
||||||
|
(point-min) (point-max))))))
|
||||||
(setq eshell-atuin--last-command-start (current-time))))
|
(setq eshell-atuin--last-command-start (current-time))))
|
||||||
|
|
||||||
(defun eshell-atuin--post-exec ()
|
(defun eshell-atuin--post-exec ()
|
||||||
|
|
@ -177,7 +181,9 @@ of the command."
|
||||||
(buf (generate-new-buffer "*atuin-output*"))
|
(buf (generate-new-buffer "*atuin-output*"))
|
||||||
;; XXX No idea why `call-process' or `start-process' don't
|
;; XXX No idea why `call-process' or `start-process' don't
|
||||||
;; work here.
|
;; work here.
|
||||||
(proc (with-environment-variables (("ATUIN_LOG" "error"))
|
(proc (with-environment-variables
|
||||||
|
(("ATUIN_LOG" "error")
|
||||||
|
("ATUIN_SESSION" eshell-atuin--session-id))
|
||||||
(start-process-shell-command "atuin-history-stop" buf
|
(start-process-shell-command "atuin-history-stop" buf
|
||||||
(string-join proc-args " ")))))
|
(string-join proc-args " ")))))
|
||||||
(set-process-sentinel
|
(set-process-sentinel
|
||||||
|
|
@ -193,11 +199,12 @@ of the command."
|
||||||
|
|
||||||
(defun eshell-atuin--init-session ()
|
(defun eshell-atuin--init-session ()
|
||||||
"Initialize `eshell-atuin' session, one session per Emacs."
|
"Initialize `eshell-atuin' session, one session per Emacs."
|
||||||
(setenv "ATUIN_SESSION"
|
(setq eshell-atuin--session-id
|
||||||
(string-trim
|
(string-trim
|
||||||
(with-output-to-string
|
(with-output-to-string
|
||||||
(with-current-buffer standard-output
|
(with-current-buffer standard-output
|
||||||
(call-process eshell-atuin-executable nil t nil "uuid"))))))
|
(call-process eshell-atuin-executable nil t nil "uuid")))))
|
||||||
|
(setenv "ATUIN_SESSION" eshell-atuin--session-id))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode eshell-atuin-mode
|
(define-minor-mode eshell-atuin-mode
|
||||||
|
|
@ -338,8 +345,10 @@ See `eshell-atuin--history-cache' on algorithm."
|
||||||
(round)
|
(round)
|
||||||
(format "%s seconds ago"))))
|
(format "%s seconds ago"))))
|
||||||
,@eshell-atuin-search-options))
|
,@eshell-atuin-search-options))
|
||||||
(ret (apply #'call-process eshell-atuin-executable
|
(ret (with-environment-variables
|
||||||
nil t nil proc-args)))
|
(("ATUIN_SESSION" eshell-atuin--session-id))
|
||||||
|
(apply #'call-process eshell-atuin-executable
|
||||||
|
nil t nil proc-args))))
|
||||||
(unless (or (= 0 ret) (= 1 ret))
|
(unless (or (= 0 ret) (= 1 ret))
|
||||||
(error "`atuin history list' retured %s: %s" ret (buffer-string)))
|
(error "`atuin history list' retured %s: %s" ret (buffer-string)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue