zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Add cd_silent option
@ 2019-04-01 20:10 dana
  0 siblings, 0 replies; only message in thread
From: dana @ 2019-04-01 20:10 UTC (permalink / raw)
  To: Zsh hackers list

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:

  https://superuser.com/questions/565310/silent-cd-using-cdpath-with-zsh
  https://superuser.com/questions/1364512/dont-show-output-of-cd
  https://github.com/robbyrussell/oh-my-zsh/issues/6066

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

  http://www.zsh.org/mla/workers/1996/msg01062.html

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
had.

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
later

(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?)

dana


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)).
 )
+pindex(CD_SILENT)
+pindex(NO_CD_SILENT)
+pindex(CDSILENT)
+pindex(NOCDSILENT)
+cindex(cd, silencing)
+cindex(autocd, silencing)
+item(tt(CD_SILENT))(
+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
+tt(POSIX_CD).
+)
 pindex(CHASE_DOTS)
 pindex(NO_CHASE_DOTS)
 pindex(CHASEDOTS)
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)
 	        printdirstack();
-        } else if (doprintdir) {
+	} else if (unset(CDSILENT) && doprintdir) {
 	    fprintdir(pwd, stdout);
 	    putchar('\n');
 	}
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 {
     CASEMATCH,
     CBASES,
     CDABLEVARS,
+    CDSILENT,
     CHASEDOTS,
     CHASELINKS,
     CHECKJOBS,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-01 20:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 20:10 [PATCH] Add cd_silent option dana

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).