Editing files as root with Emacs and Tramp


Did you know that you can use an existing non-privileged instance of Emacs to open files as root? Yep, Emacs includes a module called TRAMP which can use sudo to read and write files.

As is usually the case, I had to work sweat a little to make it work. My problem was that my zsh prompt was too fancy. The solution was to toss this conditional in at the end of my .zshrc:


if [ $TERM = "dumb" ]; then
   unsetopt zle
   export PS1="%% "
fi

This works by disabling the zsh line editor (“zle”) and setting a plain vanilla prompt (“PS1″) that tramp can recognize when it logs in.

TRAMP is a little slow on my machine but it sure beats firing up a new Emacs instance every time I want to edit `/etc/superdooper.conf`


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!