Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.2 KiB

  1. ;;; docker-tramp-compat.el --- TRAMP integration for docker containers -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015 Mario Rodas <marsam@users.noreply.github.com>
  3. ;; Author: Mario Rodas <marsam@users.noreply.github.com>
  4. ;; URL: https://github.com/emacs-pe/docker-tramp.el
  5. ;; Keywords: docker, convenience
  6. ;; Version: 0.1
  7. ;; Package-Requires: ((emacs "24"))
  8. ;; This file is NOT part of GNU Emacs.
  9. ;;; License:
  10. ;; This program is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;;; Code:
  22. (require 'tramp-sh)
  23. (when (version< tramp-version "2.3")
  24. ;; Overwrite `tramp-wait-for-output' to work with Alpine busy boxes in Tramp<2.3
  25. ;;
  26. ;; See:
  27. ;; + https://lists.gnu.org/archive/html/tramp-devel/2016-05/msg00000.html
  28. ;; + http://git.savannah.gnu.org/cgit/tramp.git/commit/?id=98a511248a9405848ed44de48a565b0b725af82c
  29. (defconst tramp-device-escape-sequence-regexp "\e[[0-9]+n"
  30. "Terminal control escape sequences for device status.")
  31. (defun tramp-wait-for-output (proc &optional timeout)
  32. "Wait for output from remote command."
  33. (unless (buffer-live-p (process-buffer proc))
  34. (delete-process proc)
  35. (tramp-error proc 'file-error "Process `%s' not available, try again" proc))
  36. (with-current-buffer (process-buffer proc)
  37. (let* (;; Initially, `tramp-end-of-output' is "#$ ". There might
  38. ;; be leading escape sequences, which must be ignored.
  39. ;; Busyboxes built with the EDITING_ASK_TERMINAL config
  40. ;; option send also escape sequences, which must be
  41. ;; ignored.
  42. (regexp (format "[^#$\n]*%s\\(%s\\)?\r?$"
  43. (regexp-quote tramp-end-of-output)
  44. tramp-device-escape-sequence-regexp))
  45. ;; Sometimes, the commands do not return a newline but a
  46. ;; null byte before the shell prompt, for example "git
  47. ;; ls-files -c -z ...".
  48. (regexp1 (format "\\(^\\|\000\\)%s" regexp))
  49. (found (tramp-wait-for-regexp proc timeout regexp1)))
  50. (if found
  51. (let (buffer-read-only)
  52. ;; A simple-minded busybox has sent " ^H" sequences.
  53. ;; Delete them.
  54. (goto-char (point-min))
  55. (when (re-search-forward "^\\(.\b\\)+$" (point-at-eol) t)
  56. (forward-line 1)
  57. (delete-region (point-min) (point)))
  58. ;; Delete the prompt.
  59. (goto-char (point-max))
  60. (re-search-backward regexp nil t)
  61. (delete-region (point) (point-max)))
  62. (if timeout
  63. (tramp-error
  64. proc 'file-error
  65. "[[Remote prompt `%s' not found in %d secs]]"
  66. tramp-end-of-output timeout)
  67. (tramp-error
  68. proc 'file-error
  69. "[[Remote prompt `%s' not found]]" tramp-end-of-output)))
  70. ;; Return value is whether end-of-output sentinel was found.
  71. found)))
  72. )
  73. (provide 'docker-tramp-compat)
  74. ;;; docker-tramp-compat.el ends here