From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jason Kim Newsgroups: gmane.emacs.devel Subject: Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) Date: Mon, 24 May 2021 10:20:15 -0700 Message-ID: References: <83v97we0ey.fsf@gnu.org> <6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com> <83cztsxvb8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------951896E38C7AFC2BA57C70A2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21533"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 Cc: Jason Kim , michael.albinus@gmx.de, shivers@cs.cmu.edu, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 24 19:23:15 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llEIN-0005Mi-HI for ged-emacs-devel@m.gmane-mx.org; Mon, 24 May 2021 19:23:15 +0200 Original-Received: from localhost ([::1]:41780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llEIM-00065r-HB for ged-emacs-devel@m.gmane-mx.org; Mon, 24 May 2021 13:23:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llEFm-00034P-6M for emacs-devel@gnu.org; Mon, 24 May 2021 13:20:35 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:34431) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llEFh-0002Dx-Mx; Mon, 24 May 2021 13:20:33 -0400 Original-Received: (Authenticated sender: jason.kim@revtera.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C0BCDC0002; Mon, 24 May 2021 17:20:20 +0000 (UTC) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=217.70.183.198; envelope-from=jason.kim@revtera.com; helo=relay6-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269781 Archived-At: This is a multi-part message in MIME format. --------------951896E38C7AFC2BA57C70A2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Wooops sent too soon. changed: identified the function touched in shell.el in commitlog Thanks! -Jason --------------951896E38C7AFC2BA57C70A2 Content-Type: text/x-patch; charset=UTF-8; name="0001-Auto-cd-support-for-lisp-shell.el.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Auto-cd-support-for-lisp-shell.el.patch" >From bbdd6f2665c70e15ccc23f48d664eb6e20df7fa6 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Mon, 24 May 2021 10:04:54 -0700 Subject: [PATCH] Auto-cd support for lisp/shell.el Added a new defcustom shell-has-auto-cd (default: nil) for users with shells like zsh that can auto-cd into a directory without typing in the "cd" command. If set to true and the command is a directory, then shell-directory-tracker processes the command (which happens to be a directory) as if it were prepended with "cd" --- lisp/shell.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/shell.el b/lisp/shell.el index 3098d3a14d..8ea6176896 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -321,6 +321,16 @@ shell-last-dir (defvar shell-dirstack-query nil "Command used by `shell-resync-dirs' to query the shell.") +(defcustom shell-has-auto-cd nil + "If non-nil, `shell-mode' handles implicit \"cd\" commands. +Implicit \"cd\" is changing the directory if the command is a directory. +You can make this variable buffer-local to change it, per shell-mode instance +Useful for shells like zsh that has this feature." + :type 'boolean + :group 'shell-directories + :version "28") + + (defvar shell-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\C-f" 'shell-forward-command) @@ -836,13 +846,15 @@ shell-directory-tracker str) ; skip whitespace (match-end 0))) (case-fold-search) - end cmd arg1) + end cmd arg1 cmd-subst-fn) (while (string-match shell-command-regexp str start) (setq end (match-end 0) cmd (comint-arguments (substring str start end) 0 0) arg1 (comint-arguments (substring str start end) 1 1)) (if arg1 (setq arg1 (shell-unquote-argument arg1))) + (if shell-has-auto-cd + (setq cmd-subst-fn (comint-substitute-in-file-name cmd))) (cond ((string-match (concat "\\`\\(" shell-popd-regexp "\\)\\($\\|[ \t]\\)") cmd) @@ -859,7 +871,9 @@ shell-directory-tracker (string-match (concat "\\`\\(" shell-chdrive-regexp "\\)\\($\\|[ \t]\\)") cmd)) - (shell-process-cd (comint-substitute-in-file-name cmd)))) + (shell-process-cd (comint-substitute-in-file-name cmd))) + ((and shell-has-auto-cd (file-directory-p cmd-subst-fn)) + (shell-process-cd cmd-subst-fn))) (setq start (progn (string-match shell-command-separator-regexp str end) ;; skip again -- 2.25.1 --------------951896E38C7AFC2BA57C70A2--