From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#16197: 24.3.50; no completion on commands following "sudo" in shell and eshell Date: Tue, 07 Jan 2014 14:11:39 +0100 Organization: Emacs Helm Message-ID: <87bnzoueb8.fsf@gmail.com> References: <87fvpolyuk.fsf@gmail.com> <87zjnshslj.fsf@gmail.com> <87vbyfoojc.fsf@gmail.com> <8738lispja.fsf@gmail.com> <8738licym6.fsf@gmail.com> <874n5kfh0x.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1389100336 5558 80.91.229.3 (7 Jan 2014 13:12:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Jan 2014 13:12:16 +0000 (UTC) Cc: 16197@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 07 14:12:23 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W0WSC-0006do-8e for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Jan 2014 14:12:20 +0100 Original-Received: from localhost ([::1]:40622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0WSB-00082g-KP for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Jan 2014 08:12:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0WS3-0007wG-09 for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2014 08:12:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0WRu-0005Gq-Un for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2014 08:12:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0WRu-0005Gm-Qt for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2014 08:12:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1W0WRt-0002EC-Vv for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2014 08:12:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Jan 2014 13:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16197 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16197-submit@debbugs.gnu.org id=B16197.13891003218557 (code B ref 16197); Tue, 07 Jan 2014 13:12:01 +0000 Original-Received: (at 16197) by debbugs.gnu.org; 7 Jan 2014 13:12:01 +0000 Original-Received: from localhost ([127.0.0.1]:40469 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W0WRr-0002Dw-6M for submit@debbugs.gnu.org; Tue, 07 Jan 2014 08:12:00 -0500 Original-Received: from mail-wg0-f45.google.com ([74.125.82.45]:40526) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W0WRo-0002Dl-LX for 16197@debbugs.gnu.org; Tue, 07 Jan 2014 08:11:57 -0500 Original-Received: by mail-wg0-f45.google.com with SMTP id y10so121945wgg.12 for <16197@debbugs.gnu.org>; Tue, 07 Jan 2014 05:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:organization:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=c+Ab6lHu5jqNI/TDDi8XV/W9S3vjLx0lDBHW30eucyc=; b=ePrWb5wQVN7dFNeePODmw2VEaS/dJl3/u43O0qciVD3sJSWiMV95WzIyBNE867zyqW k73rb1bB+e3V4suXB8m1NEjnWbyLuN4iJCnRQPzNEE5tswqYIoOgt4kf8sgFjewWWf7s 7upp4vmXDlwcccab6k5fLmTo2TbWsb4k9sxi6C79DCoi394wzunXdV+6jfBAHPfeCU9e wyHDX014HBzLfihntqUUXR+h9x3NeCnfBS+PdoowK63eEt2dnC0InxkFodoVBS6qFh/A N1NoC5qaOLSkUcVamV1QJg+ASlh07zhHNjFeK1qlD7CDw3qeHUMov4tlqMdzj92F4x0K 5Gpg== X-Received: by 10.194.237.226 with SMTP id vf2mr6325338wjc.58.1389100315654; Tue, 07 Jan 2014 05:11:55 -0800 (PST) Original-Received: from dell-14z ([37.160.108.159]) by mx.google.com with ESMTPSA id d2sm3469974wik.11.2014.01.07.05.11.52 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 05:11:54 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Sat, 04 Jan 2014 15:26:59 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:83108 Archived-At: Stefan Monnier writes: >> https://github.com/thierryvolpiatto/emacs-tv-config/blob/master/pcomplete-extension.el > > Not sure what I should look at there. For a quick test, you can load this file and do the following tests in `shell' and/or `eshell': ;; Tests ;; find . -name '*.el' | xargs et =>ok ;; sudo apt-g =>ok ;; sudo apt-get in =>ok ;; sudo apt-get -- =>ok ;; sudo apt-get - =>ok ;; sudo apt-get -V - =>ok ;; sudo apt-get -V -- =>ok ;; sudo apt-get --reinstall ins =>ok ;; sudo apt-get --reinstall install em =>ok ;; sudo - =>ok ;; sudo -p "pass" - =>ok ;; sudo -p "pass" apt-g =>ok ;; sudo -p "pass" apt-get ins =>ok ;; apt-get in =>ok ;; apt-get install em =>ok Tell me if something went wrong on these tests or if you have other cases that are not working. NOTE: [...] | xargs -0 foo is not working yet because args are not handled in pcomplete/xargs. I would do it later if you accept the patch below. > Can you send it as a patch against pcmpl-unix.el to fix pcomplete/xargs > (and add pcomplete/sudo at the same time)? * lisp/pcml-unix.el (pcomplete/sudo): New. * lisp/pcomplete.el (pcomplete-command-name): Allow extracting command-name in more complex command lines. * lisp/shell.el (shell-command-completion-function): Fix it (was not working at all). --8<---------------cut here---------------start------------->8--- Changes from master to stash 3 files changed, 52 insertions(+), 4 deletions(-) lisp/pcmpl-unix.el | 16 ++++++++++++++++ lisp/pcomplete.el | 35 ++++++++++++++++++++++++++++++++++- lisp/shell.el | 5 ++--- Modified lisp/pcmpl-unix.el diff --git a/lisp/pcmpl-unix.el b/lisp/pcmpl-unix.el index 6ac3e15..1c55f67 100644 --- a/lisp/pcmpl-unix.el +++ b/lisp/pcmpl-unix.el @@ -215,6 +215,22 @@ Includes files as well as host names followed by a colon." (pcmpl-ssh-hosts))))))) (complete-with-action action table string pred)))))) +(defun pcomplete/sudo () + (let ((pcomplete-cmd-name (pcomplete-command-name))) + (while (and (string= "sudo" pcomplete-cmd-name) + (pcomplete-match "^-" 'last)) + (when (< pcomplete-index pcomplete-last) + (pcomplete-next-arg)) + (pcomplete-opt "AbCDEegHhiKknPpSsUuVv-")) + (cond ((string= "sudo" pcomplete-cmd-name) + (while (pcomplete-here* + (funcall pcomplete-command-completion-function) + (pcomplete-arg 'last) t))) + (t + (funcall (or (pcomplete-find-completion-function + pcomplete-cmd-name) + pcomplete-default-completion-function)))))) + (provide 'pcmpl-unix) ;;; pcmpl-unix.el ends here Modified lisp/pcomplete.el diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index dbeefda..68351e2 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -633,9 +633,42 @@ user actually typed in." (message "No completions") (throw 'pcompleted nil)))) +(defvar pcomplete-special-commands '("sudo" "xargs")) (defun pcomplete-command-name () "Return the command name of the first argument." - (file-name-nondirectory (pcomplete-arg 'first))) + (let ((coms (cl-loop with lst = (reverse (pcomplete-parse-arguments)) + for str in (or (member "|" lst) + (member "||" lst) + (member "&" lst) + (member ";" lst) + lst) + for exec = (or (executable-find str) + ;; `executable-find' or 'which' + ;; doesn't return these paths. + (car (member str '("cd" "pushd" "popd")))) + when exec collect exec))) + (file-name-nondirectory + ;; we may have commands embeded in executables that looks + ;; like executables (e.g apt-get install). + ;; Assume that all executables are using only one command + ;; like this. + ;; e.g - if we have (install apt-get sudo) + ;; what we want is apt-get. + ;; - if we have (apt-get sudo) + ;; what we want is sudo, + ;; then pcomplete/sudo will check if + ;; a pcomplete handler exists for apt-get. + (cond (;; e.g (install apt-get sudo) + (> (length coms) 2) (cadr coms)) + (;; e.g (apt-get sudo) + (and (= (length coms) 2) + (member (file-name-nondirectory (cadr coms)) + pcomplete-special-commands)) + (car coms)) + (;; e.g (sudo) + (= (length coms) 1) (car coms)) + (t ;; e.g (install apt-get) + (cadr coms)))))) (defun pcomplete-match (regexp &optional index offset start) "Like `string-match', but on the current completion argument." Modified lisp/shell.el diff --git a/lisp/shell.el b/lisp/shell.el index 1d67f0b..5bb6a91 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -447,9 +447,8 @@ Thus, this does not include the shell's current directory.") This is the value of `pcomplete-command-completion-function' for --8<---------------cut here---------------end--------------->8--- Shell buffers. It implements `shell-completion-execonly' for `pcomplete' completion." - (pcomplete-here (pcomplete-entries nil - (if shell-completion-execonly - 'file-executable-p)))) + (let ((data (shell--command-completion-data))) + (and data (pcomplete-here (all-completions "" (nth 2 data)))))) (defun shell-completion-vars () "Setup completion vars for `shell-mode' and `read-shell-command'." -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997