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

[PATCH] add cdtohome setting



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@xxxxxxxxxx>
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,




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