Skip to content

Commit

Permalink
Check tramp supports docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Silex committed Aug 5, 2024
1 parent d5255a6 commit d837c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker-container.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ string that transforms the displayed values in the column."
(eshell-buffer-name (docker-utils-generate-new-buffer-name "docker" "eshell:" default-directory)))
(eshell)))

(defun docker-container-assert-tramp-docker ()
"Assert tramp docker support is available."
(unless (or (docker-utils-package-p 'docker-container)
(docker-utils-package-p 'docker-tramp))
(error "tramp docker support was not detected, try installing docker-tramp")))

;;;###autoload (autoload 'docker-container-find-directory "docker-container" nil t)
(defun docker-container-find-directory (container directory)
"Inside CONTAINER open DIRECTORY."
Expand All @@ -180,6 +186,7 @@ string that transforms the displayed values in the column."
(tramp-filename (read-directory-name "Directory: " (format "/docker:%s:/" container-name))))
(with-parsed-tramp-file-name tramp-filename nil
(list host localname))))
(docker-container-assert-tramp-docker)
(dired (format "/docker:%s:%s" container directory)))

(defalias 'docker-container-dired 'docker-container-find-directory)
Expand All @@ -192,6 +199,7 @@ string that transforms the displayed values in the column."
(tramp-filename (read-file-name "File: " (format "/docker:%s:/" container-name))))
(with-parsed-tramp-file-name tramp-filename nil
(list host localname))))
(docker-container-assert-tramp-docker)
(find-file (format "/docker:%s:%s" container file)))

;;;###autoload (autoload 'docker-container-shell "docker-container" nil t)
Expand All @@ -217,6 +225,7 @@ nil, ask the user for it."
(interactive (list
(docker-container-read-name)
current-prefix-arg))
(docker-container-assert-tramp-docker)
(let* ((shell-file-name (docker-container--read-shell read-shell))
(container-address (format "docker:%s:" container))
(file-prefix (let ((prefix (file-remote-p default-directory)))
Expand Down Expand Up @@ -251,6 +260,7 @@ nil, ask the user for it."
default directory set to workdir."
(interactive (list
(docker-container-read-name)))
(docker-container-assert-tramp-docker)
(let* ((container-address (format "docker:%s:" container))
(file-prefix (let ((prefix (file-remote-p default-directory)))
(if prefix
Expand Down
5 changes: 5 additions & 0 deletions docker-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ This has no effect on the actual value of the variable."
(-map (-partial #'plist-get it) '(:name :width :template :sort :format))
(symbol-value sym)))

(defun docker-utils-package-p (package)
"Check if PACKAGE is available."
(or (featurep package)
(ignore-errors (require package))))

(provide 'docker-utils)

;;; docker-utils.el ends here

0 comments on commit d837c7d

Please sign in to comment.