(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))))
(defun go2-tramp--completions (&optional file)
(--map (list nil it)
(go2-tramp--list-cached)))
(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 "")))
(eval-after-load 'tramp
'(progn
(go2-tramp-add-method)
(tramp-set-completion-function
go2-tramp-method go2-tramp-completion-function-alist)))
(provide 'go2-tramp)