GNU bug report logs - #16197
24.3.50; no completion on commands following "sudo" in shell and eshell

Previous Next

Package: emacs;

Reported by: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>

Date: Fri, 20 Dec 2013 08:20:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 24.3.50

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#16197: 24.3.50;
 no completion on commands following "sudo" in shell and eshell
Date: Mon, 23 Dec 2013 09:36:08 +0100
Thierry Volpiatto <thierry.volpiatto <at> gmail.com> writes:

> Hi all,
> shell and eshell are not completing commands after "sudo".
>
> For eshell what is needed is a `pcomplete/sudo' function:
>
> (defun pcomplete/sudo ()
>   (let ((prec (pcomplete-arg 'last -1)))
>     (cond ((string= "sudo" prec)
>            (while (pcomplete-here*
>                    (funcall pcomplete-command-completion-function)
>                    (pcomplete-arg 'last) t))))))
>
> For shell modify `shell-command-completion' something like this:
>
> (defun shell-command-completion ()
>   "Return the completion data for the command at point, if any."
>   (let ((filename (comint-match-partial-filename))
>         start)
>     (if (and filename
> 	     (save-match-data (not (string-match "[~/]" filename)))
> 	     (eq (setq start (match-beginning 0))
> 		 (save-excursion (shell-backward-command 1)
>                                  (if (looking-at "sudo")
>                                      start (point)))))
> 	(shell--command-completion-data))))
>

However this is not enough if one wants completion on arguments entered
after the command that is after "sudo".
For this the pcomplete/sudo function should looks like this:

--8<---------------cut here---------------start------------->8---
(defun pcomplete/sudo ()
  (let ((prec (pcomplete-arg 'last -1)))
    (cond ((string= "sudo" prec)
           (while (pcomplete-here*
                   (funcall pcomplete-command-completion-function)
                   (pcomplete-arg 'last) t)))
          (t
           (funcall (or (pcomplete-find-completion-function
                         (pcomplete-command-name))
                        pcomplete-default-completion-function))))))
--8<---------------cut here---------------end--------------->8---

However it still not working with this definition because
`pcomplete-command-name' is bad defined, thus it is crashing emacs
maybe because it sometimes try to do (file-name-nondirectory nil).
(Haven't debugged this yet).

So the function should be redefined something like this:

--8<---------------cut here---------------start------------->8---
(defun pcomplete-command-name ()
  "Return the command name of the first argument."
  (let ((com (pcomplete-arg 'first))
        (com1 (pcomplete-arg 'first 1))
        (com2 (pcomplete-arg 'last -1))
        (com3 (pcomplete-arg 'last)))
    (cond ((and (stringp com) (stringp com1)
                (not (string= com1 ""))
                (string= com "sudo"))
           (file-name-nondirectory com1))
          ((and (stringp com2) (string= com2 "sudo")
                (not (string= com3 "")))
           (file-name-nondirectory com3))
          (t
           (file-name-nondirectory com)))))
--8<---------------cut here---------------end--------------->8---

With this I have completion on arguments of commands entered after
"sudo" (only in eshell though, not shell for the moment) and emacs is
not crashing when hitting TAB.

-- 
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 





This bug report was last modified 4 years and 238 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.