Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Add cd_silent option

This is a patch/e-mail i've been sitting on for a few months because i wasn't
sure if it was too niche. But it came up on IRC again, so:

Someone on IRC complained about the way cd prints the working directory in
certain cases. I found a few other people asking about same:


A patch was submitted a very long time ago to add an option to control this:


It wasn't merged because, as pointed out in the reply, you can work around it
yourself by redirecting cd's stdout to /dev/null in an alias or function. (You
can also alias cd to pushd and set pushd_silent.) However, that doesn't affect
the implicit cd performed by auto_cd, which was the main issue the IRC user

It turns out Mikael has been patching his shell to suppress these messages for
over a decade, and the user was OK with doing that, but everyone seemed to
agree that an option would be nice too. So... here's that again, 22 years

(Another solution would be to make auto_cd execute some function if it exists,
allowing the user to wrap cd however they want. But this seems safer/easier?)


diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index bc182eb7b..903c31134 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -88,6 +88,21 @@ tt(AUTO_CD) option set) is not a directory, and does not begin with a
 slash, try to expand the expression as if it were preceded by a `tt(~)' (see
 noderef(Filename Expansion)).
+cindex(cd, silencing)
+cindex(autocd, silencing)
+Never print the working directory after a tt(cd) (whether explicit or
+implied with the tt(AUTO_CD) option set). tt(cd) normally prints the
+working directory when the argument given to it was tt(-), a stack entry, or
+the name of a directory found under tt(CDPATH). Note that this is distinct
+from tt(pushd)'s stack-printing behaviour, which is controlled by
+tt(PUSHD_SILENT). This option overrides the printing-related effects of
diff --git a/Src/builtin.c b/Src/builtin.c
index 8dcdcc024..49f017046 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -720,7 +720,7 @@ bin_set(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 /**** directory-handling builtins ****/
-int doprintdir = 0;		/* set in exec.c (for autocd) */
+int doprintdir = 0;		/* set in exec.c (for autocd, cdpath, etc.) */
 /* pwd: display the name of the current directory */
@@ -1251,7 +1251,7 @@ cd_new_pwd(int func, LinkNode dir, int quiet)
 	if (func != BIN_CD && isset(INTERACTIVE)) {
             if (unset(PUSHDSILENT) && !quiet)
-        } else if (doprintdir) {
+	} else if (unset(CDSILENT) && doprintdir) {
 	    fprintdir(pwd, stdout);
diff --git a/Src/options.c b/Src/options.c
index 600b649e4..48c14c179 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -108,6 +108,7 @@ static struct optname optns[] = {
 {{NULL, "cbases",	      0},			 CBASES},
 {{NULL, "cprecedences",	      OPT_EMULATE|OPT_NONZSH},	 CPRECEDENCES},
 {{NULL, "cdablevars",	      OPT_EMULATE},		 CDABLEVARS},
+{{NULL, "cdsilent",	      0},			 CDSILENT},
 {{NULL, "chasedots",	      OPT_EMULATE},		 CHASEDOTS},
 {{NULL, "chaselinks",	      OPT_EMULATE},		 CHASELINKS},
 {{NULL, "checkjobs",	      OPT_EMULATE|OPT_ZSH},	 CHECKJOBS},
diff --git a/Src/zsh.h b/Src/zsh.h
index 10897372b..fc3ed2127 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2348,6 +2348,7 @@ enum {

Messages sorted by: Reverse Date, Date, Thread, Author