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: Mon, 23 Dec 2013 09:36:08 +0100 Organization: Emacs Helm Message-ID: <87zjnshslj.fsf@gmail.com> References: <87fvpolyuk.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1387787842 32735 80.91.229.3 (23 Dec 2013 08:37:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 23 Dec 2013 08:37:22 +0000 (UTC) To: 16197@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 23 09:37:28 2013 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 1Vv10w-0007tK-GB for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Dec 2013 09:37:26 +0100 Original-Received: from localhost ([::1]:60794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv10w-0002R9-4g for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Dec 2013 03:37:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv10j-0002P8-9s for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:37:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vv10Z-0008L8-Om for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:37:13 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv10Z-0008L4-Kw for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:37:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Vv10Y-000581-Ng for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:37:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87fvpolyuk.fsf@gmail.com> Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 23 Dec 2013 08:37:02 +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: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.138778781419698 (code B ref -1); Mon, 23 Dec 2013 08:37:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Dec 2013 08:36:54 +0000 Original-Received: from localhost ([127.0.0.1]:35292 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vv10O-00057c-UP for submit@debbugs.gnu.org; Mon, 23 Dec 2013 03:36:53 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:49248) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vv10K-00057R-TQ for submit@debbugs.gnu.org; Mon, 23 Dec 2013 03:36:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vv10B-0008J3-33 for submit@debbugs.gnu.org; Mon, 23 Dec 2013 03:36:48 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:50359) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv10B-0008Iy-07 for submit@debbugs.gnu.org; Mon, 23 Dec 2013 03:36:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv103-00024a-KH for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:36:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vv0zw-0008HL-4T for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:36:31 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:38943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv0zv-0008GO-RE for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 03:36:24 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Vv0zu-0006vq-2G for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2013 09:36:22 +0100 Original-Received: from lbe83-2-78-243-104-167.fbx.proxad.net ([78.243.104.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 Dec 2013 09:36:22 +0100 Original-Received: from thierry.volpiatto by lbe83-2-78-243-104-167.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 Dec 2013 09:36:22 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 79 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lbe83-2-78-243-104-167.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:inclvf1r6y3m7JRUlXWRG20VG1I= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). 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:82427 Archived-At: Thierry Volpiatto 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