-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-tramp.el
33 lines (27 loc) · 1021 Bytes
/
my-tramp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;;;;;;; tramp setup ;;;;;;;
(site-lisp-path "tramp/")
(autoload 'tramp "tramp")
;; (setq tramp-default-method "scp")
;; (setq tramp-default-user "matthew")
;; (setq tramp-default-host "code.general-rotors.com")
; TRAMP reopening with sudo
(defun th-rename-tramp-buffer ()
(when (file-remote-p (buffer-file-name))
(rename-buffer
(format "%s:%s"
(file-remote-p (buffer-file-name) 'method)
(buffer-name)))))
(add-hook 'find-file-hook
'th-rename-tramp-buffer)
(defadvice find-file (around th-find-file activate)
"Open FILENAME using tramp's sudo method if it's read-only."
(if (and (not (file-writable-p (ad-get-arg 0)))
(y-or-n-p (concat "File "
(ad-get-arg 0)
" is read-only. Open it as root? ")))
(th-find-file-sudo (ad-get-arg 0))
ad-do-it))
(defun th-find-file-sudo (file)
"Opens FILE with root privileges."
(interactive "F")
(set-buffer (find-file (concat "/sudo::" file))))