Subject: bug#43055: 27.1; [PATCH] * lisp/term.el: Use correct exit status in suggested dir-tracking functions

From: Phil Sainty <[email-masked]>
Date: Wed, 26 Aug 2020 15:58:39 +1200

The shell function overrides suggested in term.el to facilitate
directory tracking cause those commands to return a success status
unconditionally:

cd()    { command cd    "$@"; printf '\033AnSiTc %s\n' "$PWD"; }
pushd() { command pushd "$@"; printf '\033AnSiTc %s\n' "$PWD"; }
popd()  { command popd  "$@"; printf '\033AnSiTc %s\n' "$PWD"; }

I.e. if the 'cd' fails, we are ignoring that and instead returning
the 'printf' exit status.

I believe these should be:

cd()    { command cd    "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
pushd() { command pushd "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
popd()  { command popd  "$@" && printf '\033AnSiTc %s\n' "$PWD"; }

If the command fails, no dir-tracking update should be needed in
Emacs (so it's fine not to do that part), and we will see the exit
status for the original command, so I think this is all that's
required.

Patch attached.

-Phil
From d5e4a6fb53315621ed161986d9d01c3c2bb74357 Mon Sep 17 00:00:00 2001
From: Phil Sainty <[email-masked]>
Date: Wed, 26 Aug 2020 15:40:33 +1200
Subject: [PATCH] * lisp/term.el: Use correct exit status in suggested
 dir-tracking functions

---
 lisp/term.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/term.el b/lisp/term.el
index 09dfeb61d1..401ee7d859 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -241,9 +241,9 @@
 ;;		printf '\033AnSiTu %s\n' "$USER"
 ;;		printf '\033AnSiTc %s\n' "$PWD"
 ;;
-;;		cd()    { command cd    "$@"; printf '\033AnSiTc %s\n' "$PWD"; }
-;;		pushd() { command pushd "$@"; printf '\033AnSiTc %s\n' "$PWD"; }
-;;		popd()  { command popd  "$@"; printf '\033AnSiTc %s\n' "$PWD"; }
+;;		cd()    { command cd    "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
+;;		pushd() { command pushd "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
+;;		popd()  { command popd  "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
 ;;
 ;;		# Use custom dircolors in term buffers.
 ;;		# eval $(dircolors $HOME/.emacs_dircolors)
-- 
2.17.1