Emacs -- dired-mode test to determine remote server name / address
Asked Answered
B

1

4

Is there a test to obtain the remote server name (e.g., localhost) or address (e.g., 12.34.56.789) in the current-buffer with dired-mode active?

I suppose I could use string-match or split-string and then equal, but I thought there might be a handy function like get server name.

iphone -- dired-directory

/ssh:root@localhost#2222:/var/mobile/Applications/F30B1574-5979-4764-8742-7F9DB2863094/Documents/.0.data:

shared server -- dired-directory

/ssh:[email protected]:/home/lawlist/public_html:
Bribe answered 30/6, 2014 at 0:2 Comment(2)
This seems to be more of a TRAMP issue than specific to DIRED.Gyniatrics
@Gyniatrics -- thank you for helping me reach the right target audience. :)Bribe
C
5

If it's tramp paths you're interested in, then you probably want to look at tramp-dissect-file-name or with-parsed-tramp-file-name. e.g.:

(tramp-file-name-host (tramp-dissect-file-name path))

If you want to exclude the port, use tramp-file-name-real-host.

You might need to check file-remote-p first, if that's not already certain; and that also leads us to a nice shortcut I'd never noticed before:

(file-remote-p path 'host)

(no port-less option here, if would seem)

Comedo answered 30/6, 2014 at 1:30 Comment(1)
Thank you very much for your help -- greatly appreciated! :) For localhost with port 2222, I ended up using the condition of (and (file-remote-p dired-directory 'localhost) (equal (tramp-file-name-real-host (tramp-dissect-file-name dired-directory)) "localhost")). For the other remote server, I'm using virtually the same thing -- just substituting localhost and replacing it with 12.34.56.789.Bribe

© 2022 - 2024 — McMap. All rights reserved.