diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c77421..1544fb01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file. ### Fixed - evil-ghostel: the editing operators and insert-state Ctrl keys drive the shell in a bridged terminal, such as a rexel or ghostel-tmux buffer. +- A `file://` link without a host, or with `localhost`, opens on the remote + host in a terminal whose `default-directory` is remote. ## [0.68.0] — 2026-11-30 diff --git a/lisp/ghostel-links.el b/lisp/ghostel-links.el index 5fcb9f7f..d217a8f5 100644 --- a/lisp/ghostel-links.el +++ b/lisp/ghostel-links.el @@ -178,10 +178,11 @@ An END-LINE also marks the lines from LINE to END-LINE as the region." (defun ghostel--open-link (url) "Open URL by scheme. -`fileref:' and `file://' open in another window, a fileref at its line -and column, a file URI at its `#23', `#L23', `#L23C5' or `#L23-L42' -fragment, marking a line range. A file URI opens even when the file does not -exist. A bare path[:LINE[:COL]] resolves against `default-directory'. +`fileref:' and `file://' open in another window, a fileref at its line and +column, a file URI at its `#23', `#L23', `#L23C5' or `#L23-L42' fragment, +marking a line range. A file URI opens even when the file does not exist; +without a host or with `localhost', it opens on the host of `default-directory'. +A bare path[:LINE[:COL]] resolves against `default-directory'. Anything else goes to `browse-url'." (when (stringp url) (cond @@ -194,11 +195,14 @@ Anything else goes to `browse-url'." (line (match-string 3 url)) (col (match-string 4 url)) (end-line (match-string 5 url)) - (file (ghostel--file-uri-decode path))) + (file (ghostel--file-uri-decode path)) + (remote (file-remote-p default-directory))) (when file (find-file-other-window (cond ((not (ghostel-local-host-p host)) (ghostel--tramp-path host file)) + ((and remote (member host '("" "localhost"))) + (concat remote file)) ((eq system-type 'windows-nt) (ghostel--windows-local-path file)) (t file))) diff --git a/test/ghostel-links-test.el b/test/ghostel-links-test.el index bff4d390..048f9ff4 100644 --- a/test/ghostel-links-test.el +++ b/test/ghostel-links-test.el @@ -188,6 +188,15 @@ row. Navigation should land on the link only once, not on each chunk." (gnu/linux "/tmp/" "file://Remote/tmp/x" "/ssh:remote:/tmp/x") (gnu/linux "/ssh:user@remote:/home/" "file://remote/tmp/x" "/ssh:user@remote:/tmp/x") + ;; No host, or localhost, is the terminal's host. + (gnu/linux "/ssh:user@remote:/home/" "file:///tmp/x#L3" + "/ssh:user@remote:/tmp/x") + (gnu/linux "/ssh:user@remote:/home/" "file://localhost/tmp/x" + "/ssh:user@remote:/tmp/x") + (gnu/linux "/ssh:user@remote:/home/" + ,(concat "file://" (system-name) "/tmp/x") "/tmp/x") + (windows-nt "/ssh:user@remote:/home/" "file:///tmp/x" + "/ssh:user@remote:/tmp/x") (windows-nt "/tmp/" "file:///C:/a%20b.txt" "C:/a b.txt") (windows-nt "/tmp/" "file://localhost/d:\\x.txt" "d:\\x.txt")))