zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: dirs builtin
@ 2002-02-13  9:36 Oliver Kiddle
  2002-02-13 17:08 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2002-02-13  9:36 UTC (permalink / raw)
  To: zsh-workers

When bash added zsh's dirs builtin, they added a few extra options.
Nothing particularly exciting but this patch adds these two:

  -c clears the stack - equivalent to dirstack=() with zsh/parameter
  -p lists stack entries on their own line (-v without the numbers)

I've not implemented -l which would expand tilde substitutions -
existing code for tilde expansions is mixed in with other expansions so
I'd have to either duplicate or pull apart existing code. Bash also
allows listing of individual stack entries with, e.g. -3. I was going
to add this but can't be bothered now.

The patch includes the documentation and completion changes. I've also
restored _directories to using _files instead of _path_files but made
it default to a description of `directory' instead of `file'. Would it
have been better to use _description instead of _wanted?

Oliver

--- Src/builtin.c	Tue Jan 29 09:59:21 2002
+++ Src/builtin.c	Sat Feb  2 16:29:08 2002
@@ -51,7 +51,7 @@
     BUILTIN("chdir", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL),
     BUILTIN("continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE,
NULL, NULL),
     BUILTIN("declare", BINF_TYPEOPTS | BINF_MAGICEQUALS |
BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AEFHLRTUZafghilrtux", NULL),
-    BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "v", NULL),
+    BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "cpv", NULL),
     BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmr",
NULL),
     BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL),
     BUILTIN("echo", BINF_PRINTOPTS | BINF_ECHOPTS, bin_print, 0, -1,
BIN_ECHO, "neE", "-"),
@@ -607,37 +607,37 @@
 {
     LinkList l;
 
-    /* with the -v option, provide a numbered list of directories,
starting at
-       zero */
     queue_signals();
-    if (ops['v']) {
+    /* with -v, -p or no arguments display the directory stack */
+    if (!(*argv || ops['c']) || ops['v'] || ops ['p']) {
 	LinkNode node;
+	char *fmt;
 	int pos = 1;
 
-	printf("0\t");
+	/* with the -v option, display a numbered list, starting at zero */
+	if (ops['v']) {
+	    printf("0\t");
+	    fmt = "\n%d\t";
+	/* with the -p option, display entries one per line */
+	} else if (ops['p'])
+	    fmt = "\n";
+	else
+	    fmt = " ";
 	fprintdir(pwd, stdout);
 	for (node = firstnode(dirstack); node; incnode(node)) {
-	    printf("\n%d\t", pos++);
+	    printf(fmt, pos++);
 	    fprintdir(getdata(node), stdout);
 	}
-	putchar('\n');
-	unqueue_signals();
-	return 0;
-    }
-    /* given no arguments, list the stack normally */
-    if (!*argv) {
-	printdirstack();
 	unqueue_signals();
+	putchar('\n');
 	return 0;
     }
     /* replace the stack with the specified directories */
     l = znewlinklist();
-    if (*argv) {
-	while (*argv)
-	    zaddlinknode(l, ztrdup(*argv++));
-	freelinklist(dirstack, freestr);
-	dirstack = l;
-    }
+    while (*argv)
+	zaddlinknode(l, ztrdup(*argv++));
+    freelinklist(dirstack, freestr);
+    dirstack = l;
     unqueue_signals();
     return 0;
 }
--- /dev/null	Sat Apr 14 12:06:21 2001
+++ Completion/Zsh/Command/_dirs	Sat Feb  2 16:40:44 2002
@@ -0,0 +1,7 @@
+#compdef dirs
+
+_arguments -s \
+  '(-)-c[clear the directory stack]' \
+  '(* -c)-v[display numbered list of directory stack]' \
+  '(* -c)-p[display directory entries on per line]' \
+  '(-)*:directory:_directories'
--- Completion/Unix/Type/_directories   Thu Jan  3 13:01:47 2002
+++ Completion/Unix/Type/_directories   Tue Feb 12 20:23:28 2002
@@ -1,3 +1,5 @@
-#compdef rmdir df du dircmp dirs
+#compdef rmdir df du dircmp
 
-_path_files -/ "$@"
+local expl
+
+_wanted directories expl directory _files -/ "$@" -
--- Doc/Zsh/builtins.yo	Mon Jan  7 15:12:50 2002
+++ Doc/Zsh/builtins.yo	Tue Feb 12 20:25:31 2002
@@ -200,15 +200,27 @@
 alias(declare)(typeset)
 findex(dirs)
 cindex(directory stack, printing)
-item(tt(dirs) [ tt(-v) ] [ var(arg) ... ])(
+xitem(tt(dirs) [ tt(-c) ] [ var(arg) ... ])
+item(tt(dirs) [ tt(-pv) ])(
 With no arguments, print the contents of the directory stack.
-If the tt(-v) option is given, number the directories
-in the stack when printing.
 Directories are added to this stack with the tt(pushd) command,
 and removed with the tt(cd) or tt(popd) commands.
 If arguments are specified, load them onto the directory stack,
 replacing anything that was there, and push the current directory
 onto the stack.
+
+startitem()
+item(tt(-c))(
+clear the directory stack.
+)
+item(tt(-p))(
+print directory entries one per line.
+)
+item(tt(-v))(
+number the directories in the stack when printing.
+)
+enditem()
+
 )
 findex(disable)
 cindex(disabling commands)


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: dirs builtin
  2002-02-13  9:36 PATCH: dirs builtin Oliver Kiddle
@ 2002-02-13 17:08 ` Bart Schaefer
  2002-02-20  9:32   ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2002-02-13 17:08 UTC (permalink / raw)
  To: Oliver Kiddle, zsh-workers

On Feb 13,  9:36am, Oliver Kiddle wrote:
}
} I've not implemented -l which would expand tilde substitutions -
} existing code for tilde expansions is mixed in with other expansions so
} I'd have to either duplicate or pull apart existing code.

The dirstack entries are already stored expanded.  All you need to do is
pass a flag through printdirstack() to fprintdir() to tell it to skip the
finddir() call and just print the directory.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: dirs builtin
  2002-02-13 17:08 ` Bart Schaefer
@ 2002-02-20  9:32   ` Oliver Kiddle
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2002-02-20  9:32 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

Bart wrote:

> On Feb 13,  9:36am, Oliver Kiddle wrote:
> }
> } I've not implemented -l which would expand tilde substitutions -
> } existing code for tilde expansions is mixed in with other
expansions 
> so
> } I'd have to either duplicate or pull apart existing code.
> 
> The dirstack entries are already stored expanded.  All you need to do

> is
> pass a flag through printdirstack() to fprintdir() to tell it to skip

> the
> finddir() call and just print the directory.

Thanks, I should have thought about that. This patch goes on top of the
previous one.

Oliver

--- Src/builtin.c      Sat Feb  2 16:29:08 2002
+++ Src/builtin.c      Tue Feb 19 21:57:46 2002
@@ -51,7 +51,7 @@
     BUILTIN("chdir", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL),
     BUILTIN("continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE,
NULL, NULL),
     BUILTIN("declare", BINF_TYPEOPTS | BINF_MAGICEQUALS |
BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AEFHLRTUZafghilrtux", NULL),
-    BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "cpv", NULL),
+    BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "clpv", NULL),
     BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmr",
NULL),
     BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL),
     BUILTIN("echo", BINF_PRINTOPTS | BINF_ECHOPTS, bin_print, 0, -1,
BIN_ECHO, "neE", "-"),
@@ -623,10 +623,16 @@
            fmt = "\n";
        else
            fmt = " ";
-       fprintdir(pwd, stdout);
+       if (ops['l'])
+           fputs(pwd, stdout);
+       else
+           fprintdir(pwd, stdout);
        for (node = firstnode(dirstack); node; incnode(node)) {
            printf(fmt, pos++);
-           fprintdir(getdata(node), stdout);
+           if (ops['l'])
+               fputs(getdata(node), stdout);
+           else
+               fprintdir(getdata(node), stdout);
        }
        unqueue_signals();
        putchar('\n');
--- Completion/Zsh/Command/_dirs	Tue Feb 19 22:36:24 2002
+++ Completion/Zsh/Command/_dirs	Tue Feb 19 22:38:10 2002
@@ -2,6 +2,7 @@
 
 _arguments -s \
   '(-)-c[clear the directory stack]' \
+  '(* -c)-l[display directory names in full]' \
   '(* -c)-v[display numbered list of directory stack]' \
   '(* -c)-p[display directory entries on per line]' \
   '(-)*:directory:_directories'
--- Doc/Zsh/builtins.yo Tue Feb 19 22:42:08 2002
+++ Doc/Zsh/builtins.yo Tue Feb 19 22:45:27 2002
@@ -201,7 +201,7 @@
 findex(dirs)
 cindex(directory stack, printing)
 xitem(tt(dirs) [ tt(-c) ] [ var(arg) ... ])
-item(tt(dirs) [ tt(-pv) ])(
+item(tt(dirs) [ tt(-lpv) ])(
 With no arguments, print the contents of the directory stack.
 Directories are added to this stack with the tt(pushd) command,
 and removed with the tt(cd) or tt(popd) commands.
@@ -212,6 +212,9 @@
 startitem()
 item(tt(-c))(
 clear the directory stack.
+)
+item(tt(-l))(
+print directory names in full instead of using of using tt(~)
expressions.
 )
 item(tt(-p))(
 print directory entries one per line.


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-20  9:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-13  9:36 PATCH: dirs builtin Oliver Kiddle
2002-02-13 17:08 ` Bart Schaefer
2002-02-20  9:32   ` Oliver Kiddle

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).