[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux e67d040 078/112: Allow crux-sudo-edit on remote files
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux e67d040 078/112: Allow crux-sudo-edit on remote files |
Date: |
Wed, 11 Aug 2021 09:57:57 -0400 (EDT) |
branch: elpa/crux
commit e67d040f506c3feaf936d3ee8b5b4fda0d5826ae
Author: dieggsy <dieggsy@protonmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Allow crux-sudo-edit on remote files
- If editing with sudo method or similar alternative, or user is 'root',
do nothing.
- If on localhost, use sudo method and switch to root user - if on
remote host, switch to root user.
- Restore place.
- Remove ido dependency.
---
crux.el | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/crux.el b/crux.el
index bb46f31..ed33230 100644
--- a/crux.el
+++ b/crux.el
@@ -456,11 +456,24 @@ See `file-attributes' for more info."
(equal (crux-file-owner-uid filename)
(user-uid)))
+(defun crux-already-root-p ()
+ (let ((remote-method (file-remote-p default-directory 'method))
+ (remote-user (file-remote-p default-directory 'user)))
+ (and remote-method
+ (or (member remote-method '("sudo" "su" "ksu" "doas"))
+ (string= remote-user "root")))))
+
(defun crux-find-alternate-file-as-root (filename)
"Wraps `find-alternate-file' with opening FILENAME as root."
- (find-alternate-file (concat "/sudo:root@localhost:" filename)))
+ (let ((remote-method (file-remote-p default-directory 'method))
+ (remote-user (file-remote-p default-directory 'user))
+ (remote-host (file-remote-p default-directory 'host))
+ (remote-localname (file-remote-p filename 'localname)))
+ (find-alternate-file (format "/%s:root@%s:%s"
+ (or remote-method "sudo")
+ (or remote-host "localhost")
+ (or remote-localname filename)))))
-(require 'ido)
;;;###autoload
(defun crux-sudo-edit (&optional arg)
"Edit currently visited file as root.
@@ -470,9 +483,20 @@ Will also prompt for a file to visit if current
buffer is not visiting a file."
(interactive "P")
(if (or arg (not buffer-file-name))
- (find-file (concat "/sudo:root@localhost:"
- (ido-read-file-name "Find file (as root): ")))
- (crux-find-alternate-file-as-root buffer-file-name)))
+ (let ((remote-method (file-remote-p default-directory 'method))
+ (remote-host (file-remote-p default-directory 'host))
+ (remote-localname (file-remote-p default-directory 'localname)))
+ (find-file (format "/%s:root@%s:%s"
+ (or remote-method "sudo")
+ (or remote-host "localhost")
+ (or remote-localname
+ (read-file-name "Find file (as root): ")))))
+
+ (if (crux-already-root-p)
+ (message "Already editing this file as root.")
+ (let ((place (point)))
+ (crux-find-alternate-file-as-root buffer-file-name)
+ (goto-char place)))))
;;;###autoload
(defun crux-reopen-as-root ()
- [nongnu] elpa/crux b923d61 082/112: Support creating shells and terminal buffers, (continued)
- [nongnu] elpa/crux b923d61 082/112: Support creating shells and terminal buffers, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux de603e9 088/112: Add function other-window-or-switch-buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 96d4faa 097/112: Silence byte-compiler warnings, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 501a43c 105/112: Placate byte-compiler, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux d989f2a 110/112: Bump copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e0457f6 103/112: Fix a major mode check, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e3e16c1 066/112: Add a missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux fa064d7 068/112: Remove a bunch of redundant progn usages, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3e07035 073/112: Add missing autoloads, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 7365fdc 075/112: Add crux-copy-file-preserve-attribute, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e67d040 078/112: Allow crux-sudo-edit on remote files,
ELPA Syncer <=
- [nongnu] elpa/crux 2a1a39a 083/112: Add a few GitHub templates, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5ba2f3b 084/112: Add a changelog, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux c014640 086/112: Tweak some wording, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux dd3f0e5 089/112: Add function crux-kill-and-join-forward, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 23ffa81 092/112: Touch up the previous commit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 519629b 094/112: Update the changelog, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 273390e 101/112: Read file name insead of raw string, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux a471cbe 102/112: Add crux-recentf-find-directory, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 6bfd212 112/112: Update my e-mail, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux ba4b05c 021/112: Support tcsh, fish and ksh for crux-find-shell-init-file, ELPA Syncer, 2021/08/11