* [PATCH] add cdtohome setting
@ 2024-06-08 5:51 Martin Tournoij
2024-06-08 7:37 ` Lawrence Velázquez
2024-06-08 11:59 ` Mikael Magnusson
0 siblings, 2 replies; 3+ messages in thread
From: Martin Tournoij @ 2024-06-08 5:51 UTC (permalink / raw)
To: zsh-workers
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,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add cdtohome setting
2024-06-08 5:51 [PATCH] add cdtohome setting Martin Tournoij
@ 2024-06-08 7:37 ` Lawrence Velázquez
2024-06-08 11:59 ` Mikael Magnusson
1 sibling, 0 replies; 3+ messages in thread
From: Lawrence Velázquez @ 2024-06-08 7:37 UTC (permalink / raw)
To: Martin Tournoij; +Cc: zsh-workers
On Sat, Jun 8, 2024, at 1:51 AM, Martin Tournoij wrote:
> A small patch to add a tcsh setting I miss.
I don't have a strong initial opinion on whether this should be
accepted or not, but...
> -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.
I don't love how many negatives and chained clauses are jammed into
this one sentence. I think something like this would be clearer:
In the first form, change the current directory to var(arg)
or to the value of tt($HOME) if var(arg) is omitted and the
tt(CD_TO_HOME) option is set; if tt(CD_TO_HOME) is unset,
var(arg) is required.
> +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.
Isn't it the other way around? The option *enables* operand-less
cd to go $HOME. (Not argument-less, because options are arguments.)
Maybe:
If set, a tt(cd) command without operands changes the
current directory to the value of tt($HOME). If unset,
tt(cd) requires at least one operand.
--
vq
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add cdtohome setting
2024-06-08 5:51 [PATCH] add cdtohome setting Martin Tournoij
2024-06-08 7:37 ` Lawrence Velázquez
@ 2024-06-08 11:59 ` Mikael Magnusson
1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2024-06-08 11:59 UTC (permalink / raw)
To: Martin Tournoij; +Cc: zsh-workers
On Sat, Jun 8, 2024 at 7:51 AM Martin Tournoij <martin@arp242.net> wrote:
>
> A small patch to add a tcsh setting I miss.
You can also just do this,
function cd() { (( $# )) || { echo >&2 cd: argument required; return 1
}; builtin cd "$@" }
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-08 12:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-08 5:51 [PATCH] add cdtohome setting Martin Tournoij
2024-06-08 7:37 ` Lawrence Velázquez
2024-06-08 11:59 ` Mikael Magnusson
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).