zsh-workers
 help / color / mirror / code / Atom feed
From: Julian Prein <druckdev@protonmail.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: [PATCH] cd: Append 2nd argument to CWD if 1st is empty
Date: Fri, 01 Dec 2023 03:11:27 +0000	[thread overview]
Message-ID: <IZyXHgegIr8a18HfmW1WE7S2UYguBiREgTX0rv0u4WXrJO92IhaP9PVRDvoiEan85dZZL6Gvi4dQeSAgTAiFWitlFReFgse2lMJvCDcsbZM=@protonmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1948 bytes --]

Hello,

Since this could break some scripts relying on that behavior, the change could
also be put behind an option that is off by default. I first wanted to hear what
the general opinion on this change is, but would happily send a v2, if
requested.

Thanks,
Julian


From fdc9b7401d10d37a927394e782071af933469a20 Mon Sep 17 00:00:00 2001
From: Julian Prein <druckdev@protonmail.com>
Date: Thu, 30 Nov 2023 19:12:33 +0100
Subject: [PATCH] cd: Append 2nd argument to CWD if 1st is empty

In cd's second form:

    cd [ -qsLP ] old new

Currently when old is empty, cd will prepend new to the name of the
current directory. As this has very limited use cases (e.g.
`cd '' /proc` when in `/sys/...`), change the behaviour of cd to
**append** new instead.
---
 Doc/Zsh/builtins.yo | 3 ++-
 Src/builtin.c       | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 8f310f6cf591..8694298aaeac 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -287,7 +287,8 @@ directory hash table.
 

 The second form of tt(cd) substitutes the string var(new)
 for the string var(old) in the name of the current directory,
-and tries to change to this new directory.
+and tries to change to this new directory. If var(old) is empty, var(new)
+is appended to the name of the current directory.
 

 The third form of tt(cd) extracts an entry from the directory
 stack, and changes to that directory.  An argument of the form
diff --git a/Src/builtin.c b/Src/builtin.c
index 9e08a1dbce99..dad9ff745a5c 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -921,6 +921,8 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
 	}
 	len1 = strlen(argv[0]);
 	len2 = strlen(argv[1]);
+	if (!len1)
+	    u = pwd + strlen(pwd);
 	len3 = u - pwd;
 	d = (char *)zalloc(len3 + len2 + strlen(u + len1) + 1);
 	strncpy(d, pwd, len3);
-- 

2.42.1

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

             reply	other threads:[~2023-12-01  3:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  3:11 Julian Prein [this message]
2023-12-01  9:21 ` Roman Perepelitsa
2023-12-01 13:32   ` Julian Prein
2023-12-01 13:51     ` Mikael Magnusson
2023-12-01 15:05       ` Julian Prein
2023-12-01 18:21     ` Lawrence Velázquez
2023-12-01 18:27       ` Roman Perepelitsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='IZyXHgegIr8a18HfmW1WE7S2UYguBiREgTX0rv0u4WXrJO92IhaP9PVRDvoiEan85dZZL6Gvi4dQeSAgTAiFWitlFReFgse2lMJvCDcsbZM=@protonmail.com' \
    --to=druckdev@protonmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).