branch: externals/dtache
commit 2e1a0d4f0efdabd352299a666352ff2d1ba1f5e8
Author: Niklas Eklund <niklas.ekl...@posteo.net>
Commit: Niklas Eklund <niklas.ekl...@posteo.net>

    Make attach handle redirect only sessions
---
 dtache-eshell.el | 31 +++++++++++++++++--------------
 dtache-shell.el  |  3 ++-
 dtache.el        | 16 ++++++++++++----
 3 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/dtache-eshell.el b/dtache-eshell.el
index ba2ad76bf5..7077261659 100644
--- a/dtache-eshell.el
+++ b/dtache-eshell.el
@@ -89,20 +89,23 @@ If prefix-argument directly DETACH from the session."
   "Attach to SESSION."
   (interactive
    (list (dtache-eshell-select-session)))
-  (cl-letf* ((dtache--dtach-mode 'attach)
-             (input
-              (dtache-dtach-command session t))
-             ((symbol-function #'eshell-add-to-history) #'ignore))
-    (eshell-kill-input)
-    ;; Hide the input from the user
-    (let ((begin (point))
-          (end))
-      (insert input)
-      (setq end (point))
-      (overlay-put (make-overlay begin end) 'invisible t)
-      (insert " "))
-    (setq dtache--buffer-session session)
-    (call-interactively #'eshell-send-input)))
+  (if (and (dtache--session-active-p session)
+           (not (dtache--session-redirect-only session)))
+      (cl-letf* ((dtache--dtach-mode 'attach)
+                 (input
+                  (dtache-dtach-command session t))
+                 ((symbol-function #'eshell-add-to-history) #'ignore))
+        (eshell-kill-input)
+        ;; Hide the input from the user
+        (let ((begin (point))
+              (end))
+          (insert input)
+          (setq end (point))
+          (overlay-put (make-overlay begin end) 'invisible t)
+          (insert " "))
+        (setq dtache--buffer-session session)
+        (call-interactively #'eshell-send-input))
+    (dtache-open-session session)))
 
 ;;;; Minor mode
 
diff --git a/dtache-shell.el b/dtache-shell.el
index 1ba19a4b10..cc56bae01f 100644
--- a/dtache-shell.el
+++ b/dtache-shell.el
@@ -98,7 +98,8 @@ This function also makes sure that the HISTFILE is disabled 
for local shells."
 cluttering the comint-history with dtach commands."
   (interactive
    (list (dtache-shell-select-session)))
-  (if (dtache--session-active-p session)
+  (if (and (dtache--session-active-p session)
+           (not (dtache--session-redirect-only session)))
       (cl-letf ((dtache-shell--current-session session)
                 (comint-input-sender #'dtache-shell--attach-input-sender)
                 ((symbol-function 'comint-add-to-input-history) (lambda (_) 
t)))
diff --git a/dtache.el b/dtache.el
index e7df59af15..cd06c06bfa 100644
--- a/dtache.el
+++ b/dtache.el
@@ -597,10 +597,12 @@ Optionally make the path LOCAL to host."
 (defun dtache-open-dwim (session)
   "Open SESSION in a do what I mean fashion."
   (cond ((dtache--session-active session)
-         (if-let ((open-fun (alist-get
-                             (dtache--session-type session) 
dtache-type-open-dispatch)))
-             (funcall open-fun session)
-           (dtache-tail-output session)))
+         (if (dtache--session-redirect-only session)
+             (dtache-tail-output session)
+           (if-let ((open-fun (alist-get
+                               (dtache--session-type session) 
dtache-type-open-dispatch)))
+               (funcall open-fun session)
+             (dtache-tail-output session))))
         ((eq 'success (dtache--session-status session))
          (dtache-open-output session))
         ((eq 'failure (dtache--session-status session))
@@ -614,6 +616,12 @@ Optionally make the path LOCAL to host."
   (dtache-update-sessions)
   (dtache--db-get-sessions))
 
+(defun dtache-shell-command-attach (session)
+  "Attach to `dtache' SESSION."
+  (let* ((dtache--current-session session)
+         (dtache--dtach-mode 'attach))
+    (dtache-start-session nil)))
+
 ;;;;; Other
 
 (defun dtache-start-session-monitor (session)

Reply via email to