summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2019-06-26 16:48:12 +0100
committerGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2019-06-26 17:19:40 +0100
commit3e3df1ef547ec330f1d8d582cd8f69e459e5384d (patch)
treeba51bf23779e2be2f4dd44cb928ff7d9ab7cad16
parentuse web-mode for TT (diff)
downloademacs-3e3df1ef547ec330f1d8d582cd8f69e459e5384d.tar.gz
emacs-3e3df1ef547ec330f1d8d582cd8f69e459e5384d.tar.bz2
emacs-3e3df1ef547ec330f1d8d582cd8f69e459e5384d.zip
tramp autocomplete for go2 and vagrant (cached)
-rw-r--r--go2-tramp.el49
-rwxr-xr-xinit.el12
2 files changed, 61 insertions, 0 deletions
diff --git a/go2-tramp.el b/go2-tramp.el
new file mode 100644
index 0000000..e44738f
--- /dev/null
+++ b/go2-tramp.el
@@ -0,0 +1,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)
diff --git a/init.el b/init.el
index e8f61bc..a41b2b9 100755
--- a/init.el
+++ b/init.el
@@ -412,3 +412,15 @@
(add-to-list 'auto-mode-alist '("\\.tt$" . web-mode))
+(require 'go2-tramp)
+(require 'vagrant-tramp)
+
+(defun dakkar-cache-vagrant (orig &rest args)
+ (let ((repo (pcache-repository "vagrant-tramp"))
+ (key 'all-boxes))
+ (if (pcache-has repo key)
+ (pcache-get repo key)
+ (let ((value (apply orig args)))
+ (pcache-put repo key value 300)
+ value))))
+(advice-add 'vagrant-tramp--all-boxes :around #'dakkar-cache-vagrant)