[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tramp-interactive: a small helper module

From: Michael Albinus
Subject: Re: tramp-interactive: a small helper module
Date: Tue, 07 Feb 2023 18:39:15 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:

> Hi Michael

Hi Pedro,

> But in a couple of words. I have a list of users I use in VMs and
> remote machines:
> -my linux user and 'student' are the two most often used.
> So when prompted 'user' the default value is the user, but if I type
> 's' <tab> I get student autocompleted
> With the host you have the same, I default to 'localhost' for VMs but
> also have a host called osm12.local (and others).
> If I put them in the host list I'll be able to press 'o' <tab> and
> have Emacs autocomplete to osm12.local.
> Regarding the port number the default for SSH is 22, right? But I can
> also input the port number for port translated VMs.

I understand the scenario. But I still don't understand why you don't
configure Tramp's existing file name completion.

First, I assume you use always "ssh" as method. In this case I recommend
an alternative Tramp file name syntax called `simplified'. Add the
following in your .emacs:

--8<---------------cut here---------------start------------->8---
(require 'tramp)
(setq tramp-default-method "ssh")
(tramp-change-syntax 'simplified)
--8<---------------cut here---------------end--------------->8---

From now on, you don't need to write "/method:user@host:/path". Instead, you
simply write "/user@host:/path" for a remote file name.

Secondly, tell Tramp which users and hosts you are interested in. By
default, Tramp scans all config files to determine possible users and
hosts. But you can give Tramp an own completion function, like this:

--8<---------------cut here---------------start------------->8---
(setq tramp-completion-use-auth-sources nil)
(defun my-tramp-completion (&rest args)
  `((,(user-login-name) "localhost") ("student" "localhost")
    (,(user-login-name) "osm12.local" ("student" "osm12.local"))))
 "ssh" '((my-tramp-completion "")))
--8<---------------cut here---------------end--------------->8---

And now, you can do "C-x C-f /alb TAB" and it expands to "/albinus@",
which is my user name. A second TAB shows you the possible completions

--8<---------------cut here---------------start------------->8---
2 possible completions:
--8<---------------cut here---------------end--------------->8---

And if you start with "C-x C-f /loc TAB", it expands already to "/localhost:".

It doesn't matter how you define your `my-tramp-completion'
function. I've shown you a fixed list, but the function could also
create the list dynamically.

If you need ports, you shall add them to the host names, like
("student" "localhost#2222")

Play with this :-)

Evertything is explained in the Tramp manual.

Best regards, Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]