about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2002-02-20 12:51:51 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2002-02-20 12:51:51 +0000
commit6febc8fe67ab920819dd0b2bbdddb4f84d991dc5 (patch)
treea4afa3a7fcf16b3b06e36381cb3c281da8f6b5d4
parent0de96fc47898c0ed4c9c8e000fb63c897fe965ae (diff)
downloadzsh-6febc8fe67ab920819dd0b2bbdddb4f84d991dc5.tar.gz
zsh-6febc8fe67ab920819dd0b2bbdddb4f84d991dc5.tar.xz
zsh-6febc8fe67ab920819dd0b2bbdddb4f84d991dc5.zip
16619, 16676: add -c, -l and -p options to the dirs builtin
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Unix/Type/_directories6
-rw-r--r--Completion/Zsh/Command/.distfiles2
-rw-r--r--Completion/Zsh/Command/_dirs8
-rw-r--r--Doc/Zsh/builtins.yo21
-rw-r--r--Src/builtin.c49
6 files changed, 65 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 189a29073..b6f213986 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-02-20  Oliver Kiddle  <opk@zsh.org>
+
+	* 16619, 16676: Src/builtin.c, Doc/Zsh/builtins.yo,
+	Completion/Zsh/Command/_dirs, Completion/Unix/Type/_directories:
+	add -c, -l and -p options to the dirs builtin for bash compatibility
+
 2002-02-19  Clint Adams  <clint@zsh.org>
 
 	* 16673: zshconfig.ac, Doc/Zsh/.distfiles, Doc/Zsh/mod_langinfo.yo,
diff --git a/Completion/Unix/Type/_directories b/Completion/Unix/Type/_directories
index cb1b3fd44..cdf76e443 100644
--- a/Completion/Unix/Type/_directories
+++ b/Completion/Unix/Type/_directories
@@ -1,3 +1,5 @@
-#compdef rmdir df du dircmp dirs
+#compdef rmdir df du dircmp
 
-_path_files -/ "$@"
+local expl
+
+_wanted directories expl directory _files -/ "$@" -
diff --git a/Completion/Zsh/Command/.distfiles b/Completion/Zsh/Command/.distfiles
index a3762d14a..40275afbe 100644
--- a/Completion/Zsh/Command/.distfiles
+++ b/Completion/Zsh/Command/.distfiles
@@ -1,7 +1,7 @@
 DISTFILES_SRC='
 .distfiles
 _alias     _disable  _jobs_builtin  _read    _ttyctl    _which     _zstyle
-_autoload  _echotc   _kill          _sched   _typeset   _zcompile
+_autoload  _echotc   _kill          _sched   _typeset   _zcompile  _dirs
 _bindkey   _echoti   _limit         _set     _ulimit    _zed
 _builtin   _emulate  _mere          _setopt  _unhash    _zftp
 _cd        _enable   _precommand    _source  _unsetopt  _zle
diff --git a/Completion/Zsh/Command/_dirs b/Completion/Zsh/Command/_dirs
new file mode 100644
index 000000000..11d9a2b40
--- /dev/null
+++ b/Completion/Zsh/Command/_dirs
@@ -0,0 +1,8 @@
+#compdef dirs
+
+_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'
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 15b8ba23e..dadbbbca5 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -200,15 +200,30 @@ var(n)-1 loops and resume at the var(n)th enclosing loop.
 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(-lpv) ])(
 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(-l))(
+print directory names in full instead of using of using tt(~) expressions.
+)
+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)
diff --git a/Src/builtin.c b/Src/builtin.c
index 35cff6420..2165b1864 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -51,7 +51,7 @@ static struct builtin builtins[] =
     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, "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", "-"),
@@ -607,37 +607,44 @@ bin_dirs(char *name, char **argv, char *ops, int func)
 {
     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");
-	fprintdir(pwd, stdout);
+	/* 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 = " ";
+	if (ops['l'])
+	    fputs(pwd, stdout);
+	else
+	    fprintdir(pwd, stdout);
 	for (node = firstnode(dirstack); node; incnode(node)) {
-	    printf("\n%d\t", pos++);
-	    fprintdir(getdata(node), stdout);
+	    printf(fmt, pos++);
+	    if (ops['l'])
+		fputs(getdata(node), stdout);
+	    else
+		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;
 }