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>2020-09-28 10:51:40 +0100
commit76660869296e6662f78ca8785276bea48fae5522 (patch)
treef1b32a6fae2cf93197a862b0a31171d1548d8b7c
parentuse web-mode for TT (diff)
downloademacs-76660869296e6662f78ca8785276bea48fae5522.tar.gz
emacs-76660869296e6662f78ca8785276bea48fae5522.tar.bz2
emacs-76660869296e6662f78ca8785276bea48fae5522.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 6953256..4ef2d7a 100755
--- a/init.el
+++ b/init.el
@@ -418,3 +418,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)