Fixed sudo edit on remote files

The previous implementation failed, if the
remote user was given only implicitly.
This commit is contained in:
Ralf Beckmann 2019-11-03 02:00:04 +01:00
parent f2906b073f
commit 68e56025bc

View file

@ -319,9 +319,14 @@ file if it exists, without confirmation."
(interactive "FOpen file as root: ") (interactive "FOpen file as root: ")
(when (file-writable-p file) (when (file-writable-p file)
(user-error "File is user writeable, aborting sudo")) (user-error "File is user writeable, aborting sudo"))
(find-file (if (file-remote-p file) (let* ((host (or (file-remote-p file 'host) "localhost"))
(concat "/" (file-remote-p file 'method) ":" (file-remote-p file 'user) "@" (file-remote-p file 'host) "|sudo:root@" (file-remote-p file 'host) ":" (file-remote-p file 'localname)) (user-host (if-let (( user (file-remote-p file 'user)))
(concat "/sudo:root@localhost:" file)))) (concat user "@" host)
host))
(hop1 (when (file-remote-p file) (concat "/" (file-remote-p file 'method) ":" user-host)))
(sep (if hop1 "|" "/"))
(hop2 (concat "sudo:root@" host ":" (or (file-remote-p file 'localname) file))))
(find-file (concat hop1 sep hop2))))
;;;###autoload ;;;###autoload
(defun doom/sudo-this-file () (defun doom/sudo-this-file ()