Skip to content

Commit

Permalink
feat: New command mistty-docker to connect to a docker instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
szermatt committed Dec 4, 2024
1 parent 71feed0 commit de9da93
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ their behavior and arguments:
.. index::
pair: command; mistty-in-project
pair: command; mistty-ssh
pair: command; mistty-docker

- :kbd:`M-x mistty-in-project` creates a new MisTTY buffer in the
root directory of the current project the first time it is called.
Expand All @@ -112,6 +113,11 @@ their behavior and arguments:
another host using SSH. This is just a shortcut that uses TRAMP to
connect to a remote host. See :ref:`remote_shells` for details.

- :kbd:`M-x mistty-docker` creates a new MisTTY buffer connected to
a docker instance. This requires the docker command-line tool to
be installed. This is just a shortcut that uses TRAMP to connect
to a remote host. See :ref:`remote_shells` for details.

.. _term-vs-scroll:

Terminal vs. Scrollback
Expand Down
40 changes: 39 additions & 1 deletion mistty-launch.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
(require 'pcmpl-unix)

(defvar mistty-ssh-history nil
"History variable for host completion for mistty-ssh.")
"History variable for host completion for `mistty-ssh'.")

(defvar mistty-docker-history nil
"History variable for host completion for `mistty-docker'.")

(defvar mistty-docker-exe "docker"
"Path to the docker command-line tool.
This is used by `mistty-docker'")

;;;###autoload
(defun mistty-ssh (&optional host command other-window)
Expand All @@ -23,3 +31,33 @@ details."
(let ((default-directory (format "/ssh:%s:~" host)))
(cd default-directory) ;; Connect, ask password
(mistty-create command other-window)))

;;;###autoload
(defun mistty-docker (&optional instance command other-window)
"Connect to a docker instance in a MisTTY buffer.
This is a convenience function that uses TRAMP to connect to a
host and open a shell to it. For more control, run
C-u \\[mistty-create]. That'll allow you to setup any TRAMP
remote path you'd like without restrictions.
See Info Node `(mistty)Remote Shells with TRAMP' for details.
Note that docker instances often run older versions of Bash;
MisTTY will work on Bash versions < 5.1, with some limitations.
Additionally, for Bash 4.3 and earlier, you might have to set
`mistty-set-EMACS' to non-nil for directory tracking to work. You
can set it per instance as a connection-local variable. See Info
Anchor `(mistty)shells bash-dirtrack' for details."
(interactive
(list
(completing-read
"Instance: "
(string-split
(shell-command-to-string
(concat mistty-docker-exe " ps --format '{{.Names}}'"))
"\n" 'omit-nulls "[[:space:]]+")
nil nil nil 'mistty-docker-history)))
(let ((default-directory (format "/docker:%s:~" instance)))
(cd default-directory) ;; Connect, ask password
(mistty-create command other-window)))
7 changes: 7 additions & 0 deletions mistty.texi
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ details.
@geindex command; mistty-in-project
@geindex command; mistty-ssh
@geindex command; mistty-docker
@itemize -
Expand All @@ -306,6 +307,12 @@ project-kill-buffer-conditions} about MisTTY.
@code{M-x mistty-ssh} creates a new MisTTY buffer connected to
another host using SSH. This is just a shortcut that uses TRAMP to
connect to a remote host. See @ref{d,,Remote Shells with TRAMP} for details.
@item
@code{M-x mistty-docker} creates a new MisTTY buffer connected to
a docker instance. This requires the docker command-line tool to
be installed. This is just a shortcut that uses TRAMP to connect
to a remote host. See @ref{d,,Remote Shells with TRAMP} for details.
@end itemize
@end quotation

Expand Down

0 comments on commit de9da93

Please sign in to comment.