From 3e3df1ef547ec330f1d8d582cd8f69e459e5384d Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Wed, 26 Jun 2019 16:48:12 +0100 Subject: tramp autocomplete for go2 and vagrant (cached) --- go2-tramp.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ init.el | 12 ++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 go2-tramp.el 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) -- cgit v1.2.3