]> git.armaanb.net Git - config.org.git/commitdiff
Add doas-edit function
authorArmaan Bhojwani <me@armaanb.net>
Sun, 16 May 2021 23:32:14 +0000 (19:32 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 16 May 2021 23:32:14 +0000 (19:32 -0400)
config.org

index 6a21b86036e8640eaa0f18444c225b1e0b3bfdc9..3d8019686d626433b8c726938d760d8d3a94698c 100644 (file)
@@ -608,6 +608,24 @@ Abbreviate things!
 #+begin_src emacs-lisp
   (setq ispell-silently-savep t)
 #+end_src
+** Open file as root
+#+begin_src emacs-lisp
+  (defun doas-edit (&optional arg)
+    "Edit currently visited file as root.
+
+    With a prefix ARG prompt for a file to visit.
+    Will also prompt for a file to visit if current
+    buffer is not visiting a file.
+
+    Modified from Emacs Redux."
+    (interactive "P")
+    (if (or arg (not buffer-file-name))
+        (find-file (concat "/doas:root@localhost:"
+                           (ido-read-file-name "Find file(as root): ")))
+      (find-alternate-file (concat "/doas:root@localhost:" buffer-file-name))))
+
+    (global-set-key (kbd "C-x C-r") #'doas-edit)
+#+end_src
 * Keybindings
 ** Switch windows
 #+begin_src emacs-lisp