Create function open-this-file-as-other-user
It opens the current file as the specified user or root.
This commit is contained in:
parent
50d518a906
commit
ccdc042a89
1
init.el
1
init.el
@ -827,6 +827,7 @@
|
||||
(load "buf-manipulation.el")
|
||||
(load "text-manip")
|
||||
(load "frame-manip")
|
||||
(load "file-manip")
|
||||
|
||||
;; Define aliases
|
||||
(defalias 'yes-or-no-p 'y-or-n-p)
|
||||
|
13
lisp/file-manip.el
Normal file
13
lisp/file-manip.el
Normal file
@ -0,0 +1,13 @@
|
||||
(defun open-this-file-as-other-user (user)
|
||||
"Edit current file as USER, using `tramp' and `sudo'. If the current
|
||||
buffer is not visiting a file, prompt for a file name."
|
||||
(interactive "sEdit as user (default: root): ")
|
||||
(when (string= "" user)
|
||||
(setq user "root"))
|
||||
(let* ((filename (or buffer-file-name
|
||||
(read-file-name (format "Find file (as %s): "
|
||||
user))))
|
||||
(tramp-path (concat (format "/sudo:%s@localhost:" user) filename)))
|
||||
(if buffer-file-name
|
||||
(find-alternate-file tramp-path)
|
||||
(find-file tramp-path))))
|
Loading…
Reference in New Issue
Block a user