Consider current buffer's file when sudo-editing
If doom/sudo-find-file is invoked with a file that is equal to the current buffer's file, kill that buffer since it is probably not needed anymore.
This commit is contained in:
parent
68e56025bc
commit
7a810d53a0
1 changed files with 12 additions and 9 deletions
|
@ -317,16 +317,19 @@ file if it exists, without confirmation."
|
||||||
(defun doom/sudo-find-file (file)
|
(defun doom/sudo-find-file (file)
|
||||||
"Open FILE as root."
|
"Open FILE as root."
|
||||||
(interactive "FOpen file as root: ")
|
(interactive "FOpen file as root: ")
|
||||||
(when (file-writable-p file)
|
|
||||||
(user-error "File is user writeable, aborting sudo"))
|
|
||||||
(let* ((host (or (file-remote-p file 'host) "localhost"))
|
(let* ((host (or (file-remote-p file 'host) "localhost"))
|
||||||
(user-host (if-let (( user (file-remote-p file 'user)))
|
(f (concat "/" (when (file-remote-p file)
|
||||||
(concat user "@" host)
|
(concat (file-remote-p file 'method) ":"
|
||||||
host))
|
(if-let (user (file-remote-p file 'user))
|
||||||
(hop1 (when (file-remote-p file) (concat "/" (file-remote-p file 'method) ":" user-host)))
|
(concat user "@" host)
|
||||||
(sep (if hop1 "|" "/"))
|
host)
|
||||||
(hop2 (concat "sudo:root@" host ":" (or (file-remote-p file 'localname) file))))
|
"|"))
|
||||||
(find-file (concat hop1 sep hop2))))
|
"sudo:root@" host
|
||||||
|
":" (or (file-remote-p file 'localname)
|
||||||
|
file))))
|
||||||
|
(if (and buffer-file-name (equal file (file-truename buffer-file-name)))
|
||||||
|
(find-alternate-file f)
|
||||||
|
(find-file f))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/sudo-this-file ()
|
(defun doom/sudo-this-file ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue