summaryrefslogtreecommitdiff
path: root/go2-tramp.el
blob: 9db7bd7865d3acb559c05fb4dc037601a7358a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(require 'tramp)
(require 'pcache)
 
(defconst go2-tramp-method "go2")
 
(defconst go2-tramp-ssh
  (shell-quote-argument
   (executable-find "go2")))
 
(defun go2-tramp--list ()
  (let* ((go2-cmd "go2 list .")
         (go2-raw (shell-command-to-string go2-cmd))
         (go2-lines (split-string go2-raw "\n")))
    go2-lines))
 
(defun go2-tramp--list-cached ()
  (let ((repo (pcache-repository 'go2-tramp))
        (key 'list))
    (if (pcache-has repo key)
        (pcache-get repo key)
      (let ((value (go2-tramp--list)))
        (pcache-put repo key value 300)
        value))))
 
;;;###autoload
(defun go2-tramp--completions (&optional file)
  (--map (list nil it)
         (go2-tramp--list-cached)))
 
;;;###autoload
(defun go2-tramp-add-method ()
  (add-to-list 'tramp-methods
               `(,go2-tramp-method
                 (tramp-login-program     ,go2-tramp-ssh)
                 (tramp-login-args        (("connect") ("%h")))
                 (tramp-remote-shell      "/bin/sh")
                 (tramp-remote-shell-args ("-c")))))
 
(defconst go2-tramp-completion-function-alist
  '((go2-tramp--completions  "")))
 
;;;###autoload
(eval-after-load 'tramp
  '(progn
     (go2-tramp-add-method)
     (tramp-set-completion-function
      go2-tramp-method go2-tramp-completion-function-alist)))
 
(provide 'go2-tramp)