help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding simpler better sudo for Emacs


From: Jean Louis
Subject: Re: Finding simpler better sudo for Emacs
Date: Tue, 30 Mar 2021 14:05:19 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* Michael Albinus <michael.albinus@gmx.de> [2021-03-30 13:53]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > How to check if default directory is on local file system?
> 
> (file-remote-p default-directory)
> 
> nil if you are on your local host, non-nil otherwise.

Thank you, this time I was M-x apropos-ing but did not find it so
fast.

Side note on tramp, I have filed a bug on Dired/Tramp as if there is
local directory /scp:static: and I try to enter that directory I am
connected with Tramp to my remote static (hostname defined in
/etc/hosts or ~/.authinfo) server. But Dired should recognize that
marked file was on the local directory and should not go into remote
one.

In that sense if there is local directory "/scp:static:" then this
function does not work well:

(file-remote-p "/scp:static:") → "/scp:static:" while you said it
should give nil if it is local directory.

(file-remote-p "/scp:google.com:") → "/scp:google.com:" -- so this
seem that it is checking it by prefix.

That means that users are not supposed to make such local directories,
for example making a local directory /sudo: or /scp:hostname: and
similar would make Tramp fail. Emacs and Tramp rely on improbability
that users would never make such local directories. Copy and rename of
files into such local directories would probably fail, as Tramp would
try to copy it remotely.

Regarding my function, I like it to be executed only locally, and I
will skip Tramp usage for a while.

(defun sudo (arguments)
  "Executes list ARGUMENTS with system command `sudo'."
  (let ((not-remote (not (file-remote-p default-directory))))
    (if not-remote
        (let* ((command (format "sudo su -c -- root -c \"%s\"" (string-join 
(list arguments))))
               (return (shell-command-to-string command)))
          return)
      (message "This `sudo' does not work on remote directory: %s" 
default-directory))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns



reply via email to

[Prev in Thread] Current Thread [Next in Thread]