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: Fri, 7 May 2021 09:51:08 -0700 Message-ID: <6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com> References: <83v97we0ey.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------4700A9F1EBB79427F9DC7542" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6883"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 Cc: emacs-devel@gnu.org, shivers@cs.cmu.edu, jason.kim@revtera.com To: Eli Zaretskii , michael.albinus@gmx.de Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 07 18:52:11 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 1lf3hz-0001fl-1l for ged-emacs-devel@m.gmane-mx.org; Fri, 07 May 2021 18:52:11 +0200 Original-Received: from localhost ([::1]:38018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf3hy-00021Z-51 for ged-emacs-devel@m.gmane-mx.org; Fri, 07 May 2021 12:52:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf3h2-0001Da-8H for emacs-devel@gnu.org; Fri, 07 May 2021 12:51:12 -0400 Original-Received: from mr85p00im-zteg06012001.me.com ([17.58.23.197]:53566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf3h0-0000Kd-GZ for emacs-devel@gnu.org; Fri, 07 May 2021 12:51:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1620406269; bh=cZL9pmE8k2mTroB0SCCPvgtHDXttT66FiRQuHgOG/sw=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type; b=FOPcuERKnZ6HmL07Fvic6qbA4JLrNG88Dq7qtOzZySZ7xERBNQCcfq4qUGcKSe9/E LOwU1U0VFUw0oTs4a1TESw80u7dRy/poOfRNy+weFwwkCt+BvKAShrhzzvFcTqecmW k/sGcvNgKUCR7f0tyg6AzXWCOkqaH1gLcxt+Sae2XRd8V5RA9Il8MVfLWQwiTkVp5D OWvMkCzzpRZt9DV336cpv5u8sxNosgg/YQiNB5vfyuu4eaFoqTOaE9QjLB6Ud3B2ZW L28ji88AcQfr9Lw4zIAunGdzn8V8Wl5W5nrHjnXqEIVnE/3jYmHYusyqGk4gsDbO55 LGs67KFXBWTVQ== Original-Received: from [10.58.18.13] (unknown [143.244.48.59]) by mr85p00im-zteg06012001.me.com (Postfix) with ESMTPSA id C0A9BA0080E; Fri, 7 May 2021 16:51:08 +0000 (UTC) In-Reply-To: Content-Language: en-US X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.391,18.0.761,17.0.607.475.0000000_definitions?= =?UTF-8?Q?=3D2021-05-07=5F04:2021-05-06=5F01,2021-05-07=5F04,2020-04-07?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2105070110 Received-SPF: pass client-ip=17.58.23.197; envelope-from=jason.w.kim@icloud.com; helo=mr85p00im-zteg06012001.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:269007 Archived-At: This is a multi-part message in MIME format. --------------4700A9F1EBB79427F9DC7542 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, enclosed is what I hope is an acceptable git-format-patch for this tiny change. If not, please let me know how to fix! Thanks! -Jason --------------4700A9F1EBB79427F9DC7542 Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-a-defcustom-to-shell-mode-to-handle-auto-cd-feat.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Add-a-defcustom-to-shell-mode-to-handle-auto-cd-feat.pa"; filename*1="tch" >From 7dca68a6289abb1800b2dccfd26efe0e85aad6a4 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Fri, 7 May 2021 09:41:11 -0700 Subject: [PATCH] Add a defcustom to shell-mode to handle auto-cd feature (e.g. zsh) shell-has-auto-cd is a new defcustom (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-mode processes the command (which happens to be a directory) as if it were prepended with "cd" --- lisp/shell.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lisp/shell.el b/lisp/shell.el index 3098d3a14d..8b3499ccb4 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -321,6 +321,13 @@ Thus, this does not include the shell's current directory.") (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' will automatically process implicit \"cd\" commands. +Implicit \"cd\" is changing the directory if the command happens to be 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.") + + (defvar shell-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\C-f" 'shell-forward-command) @@ -836,13 +843,15 @@ Environment variables are expanded, see function `substitute-in-file-name'." 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 +868,9 @@ Environment variables are expanded, see function `substitute-in-file-name'." (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 --------------4700A9F1EBB79427F9DC7542--