1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-11-01 18:30:55 +01:00

16619, 16676: add -c, -l and -p options to the dirs builtin

This commit is contained in:
Oliver Kiddle 2002-02-20 12:51:51 +00:00
parent 0de96fc478
commit 6febc8fe67
6 changed files with 65 additions and 27 deletions

View file

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

View file

@ -1,3 +1,5 @@
#compdef rmdir df du dircmp dirs
#compdef rmdir df du dircmp
_path_files -/ "$@"
local expl
_wanted directories expl directory _files -/ "$@" -

View file

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

View file

@ -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'

View file

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

View file

@ -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);
}
unqueue_signals();
putchar('\n');
unqueue_signals();
return 0;
}
/* given no arguments, list the stack normally */
if (!*argv) {
printdirstack();
unqueue_signals();
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;
}