Emacs: edit root files without tramp

Here you can open the root file in a non-root run emacs:

erf () { SUDO_EDITOR="emacsclient -n -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground 

It asks for the root password, and after entering it, it opens a copy of the file in /tmp . Example:

 $ cd /etc/apt $ erf sources.list 

Opens: sourcesXXiOSmYN.list . So I edit this thing and save it with Cx Cs - but it does not save:

 $ sudoedit: sources.list unchanged 

How can I save this? (the function will be very neat)

Edit

  erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground 

wraps it up. Save the file and either destroy the buffer or Cx # . He works.

+4
linux emacs ubuntu sudo kubuntu
01 Oct '12 at 11:21
source share
2 answers

Drop the -n option. FWIW I use

 alias E="SUDO_EDITOR=\"emacsclient -c -a emacs\" sudoedit" 

taken somewhere ...

+5
01 Oct
source share

I do not use emacs, but what is wrong with

 export EDITOR=emacs # or export VISUAL=emacs sudoedit some-root-file 

? Put the export line in your .bashrc and you're done.

0
May 09 '13 at 10:46
source share



All Articles