zsh-workers
 help / color / mirror / code / Atom feed
From: "Martin Tournoij" <martin@arp242.net>
To: zsh-workers@zsh.org
Subject: [PATCH] add cdtohome setting
Date: Sat, 08 Jun 2024 06:51:16 +0100	[thread overview]
Message-ID: <3bc6f058-4394-4b64-bd2e-44f7efbd5688@app.fastmail.com> (raw)

A small patch to add a tcsh setting I miss.

I'm not sure if I got the documentation right; I spent quite some time with
the "yodl" tool, but it always seems to generate empty manpages on "make", and
manually trying to use it gives me errors I don't really understand. I'm
probably using it wrong, or something. I kind of gave up on that.

Please CC me in replies, as I'm not subscribed to this list.

Thanks,
Martin

--- patch ---

commit 6f2c688fe
Author: Martin Tournoij <martin@arp242.net>
Date:   Sat Jun 8 06:28:08 2024 +0100

    add cdtohome setting
    
    So just "cd" without arguments won't go to ~; I accidentally type "cd"
    too often. The "cdtohome" name was taken from tcsh.
    
    Example:
    
        % pwd
        /home/martin/src/zsh
    
        % cd
        % pwd
        /home/martin
    
        % cd -
        % setopt no_cdtohome
        % pwd
        /home/martin/src/zsh
    
        % cd
        cd: argument required
        % pwd
        /home/martin/src/zsh
    
        % cd ~
        % pwd
        /home/martin

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 7a9684ac8..5bd11ef79 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -260,10 +260,11 @@ cindex(directories, changing)
 xitem(tt(cd) [ tt(-qsLP) ] [ var(arg) ])
 xitem(tt(cd) [ tt(-qsLP) ] var(old) var(new))
 item(tt(cd) [ tt(-qsLP) ] {tt(PLUS())|tt(-)}var(n))(
-Change the current directory.  In the first form, change the
-current directory to var(arg), or to the value of tt($HOME) if
-var(arg) is not specified.  If var(arg) is `tt(-)', change to the
-previous directory.
+Change the current directory.  In the first form, change the current
+directory to var(arg), or to the value of tt($HOME) if var(arg) is not
+specified unless the tt(CD_TO_HOME) option is not set, in which case
+var(arg) is required. If var(arg) is `tt(-)', change to the previous
+directory.
 
 Otherwise, if var(arg) begins with a slash, attempt to change to the
 directory given by var(arg).
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index c3af8dd33..af830e62d 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -91,6 +91,13 @@ 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_TO_HOME)
+pindex(NO_CD_TO_HOME)
+pindex(CDTOHOME)
+pindex(NOCDTOHOME)
+item(tt(CD_TO_HOME))(
+Don't go to home when using tt(cd) without any arguments.
+)
 pindex(CD_SILENT)
 pindex(NO_CD_SILENT)
 pindex(CDSILENT)
diff --git a/Src/builtin.c b/Src/builtin.c
index 7bfb1ce1d..e0811daa0 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -882,6 +882,10 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
 	if (dir)
 	    zinsertlinknode(dirstack, dir, getlinknode(dirstack));
 	else if (func != BIN_POPD) {
+	    if (!isset(CDTOHOME)) {
+		zwarnnam(nam, "argument required");
+		return NULL;
+            }
 	    if (!home) {
 		zwarnnam(nam, "HOME not set");
 		return NULL;
diff --git a/Src/options.c b/Src/options.c
index a0e1aa024..bf8babed3 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -109,6 +109,7 @@ static struct optname optns[] = {
 {{NULL, "cbases",	      0},			 CBASES},
 {{NULL, "cprecedences",	      OPT_EMULATE|OPT_NONZSH},	 CPRECEDENCES},
 {{NULL, "cdablevars",	      OPT_EMULATE},		 CDABLEVARS},
+{{NULL, "cdtohome",	      OPT_ALL},			 CDTOHOME},
 {{NULL, "cdsilent",	      0},			 CDSILENT},
 {{NULL, "chasedots",	      OPT_EMULATE},		 CHASEDOTS},
 {{NULL, "chaselinks",	      OPT_EMULATE},		 CHASELINKS},
diff --git a/Src/zsh.h b/Src/zsh.h
index 090abf8f5..52f80f055 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2390,6 +2390,7 @@ enum {
     CASEPATHS,
     CBASES,
     CDABLEVARS,
+    CDTOHOME,
     CDSILENT,
     CHASEDOTS,
     CHASELINKS,


             reply	other threads:[~2024-06-08  5:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08  5:51 Martin Tournoij [this message]
2024-06-08  7:37 ` Lawrence Velázquez
2024-06-08 11:59 ` Mikael Magnusson

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=3bc6f058-4394-4b64-bd2e-44f7efbd5688@app.fastmail.com \
    --to=martin@arp242.net \
    --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).