Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Add cd_silent option
- X-seq: zsh-workers 44198
- From: dana <dana@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Add cd_silent option
- Date: Mon, 1 Apr 2019 15:10:00 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=0BvCTm71R108wksxdPfhlIn6OCX4Bk5VFeSgJSvHtfU=; b=g1dYHm9OomQPIjAIpehgRSEqPWztnmvnXir7SY0aOXfM1Ihg2dcBiKHMFRNBJ7v4Pf 6TjYc3elDDWAiURqrDTFU9lGyl4OZFoBNtY+/n9TSOsEAWVoy44nOsXc0MWrmEH0bsra hsNTc5SPXFd64sBkuyKAGG9CpfHx1Oop5xwXVENIXMClqfCGGKuqroQBZ0Y3vgL0HIQ3 NahTfDTVuSB32joSS090hm1izT8eFMoYs2cZnUA+6XIQv0frLPLZTyNuTPB6UUPoBEmo anNJxpGoGYCD9QnhE/B8JbiFB0DAkxp85jV0LRRe3g+qiMfPLZYINurorN5235Rn/RJd 4XEg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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,
Messages sorted by:
Reverse Date,
Date,
Thread,
Author