Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created May 26, 2017 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sideshowcoder/d1553b660a223f21c1701d03a1e382ca to your computer and use it in GitHub Desktop.
Save sideshowcoder/d1553b660a223f21c1701d03a1e382ca to your computer and use it in GitHub Desktop.
;; automatically open a file as sudo unless we have permission to write it
;; already, after all this is my machine and I can do what I want!
(defadvice ido-find-file (after find-file-sudo activate)
"Find file as root if necessary."
(unless (and buffer-file-name
(file-writable-p buffer-file-name))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment