comparison scripts/miscellaneous/ls.m @ 6115:bade9ff1814b

[project @ 2006-10-27 17:58:06 by jwe]
author jwe
date Fri, 27 Oct 2006 17:58:06 +0000
parents
children f6d78960f674
comparison
equal deleted inserted replaced
6114:a0dafb51dd06 6115:bade9ff1814b
1 ## Copyright (C) 2006 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
19
20 ## -*- texinfo -*-
21 ## @deffn {Command} ls options
22 ## List directory contents. For example,
23 ##
24 ## @example
25 ## ls -l
26 ## @print{} total 12
27 ## @print{} -rw-r--r-- 1 jwe users 4488 Aug 19 04:02 foo.m
28 ## @print{} -rw-r--r-- 1 jwe users 1315 Aug 17 23:14 bar.m
29 ## @end example
30 ##
31 ## The @code{dir} and @code{ls} commands are implemented by calling your
32 ## system's directory listing command, so the available options may vary
33 ## from system to system.
34 ## @seealso{dir, stat, readdir, glob, filesep, ls_command}
35 ## @end deffn
36
37 ## Author: jwe
38
39 ## PKG_ADD: mark_as_command ls
40
41 function retval = ls (varargin)
42
43 global __ls_command__;
44
45 if (isempty (__ls_command__) || ! ischar (__ls_command__))
46 ## Initialize value for __ls_command__.
47 ls_command ();
48 endif
49
50 if (iscellstr (varargin))
51
52 args = tilde_expand (varargin);
53
54 cmd = sprintf ("%s ", __ls_command__, args{:});
55
56 if (page_screen_output ())
57
58 [status, output] = system (cmd);
59
60 if (status == 0)
61 puts (output);
62 else
63 error ("ls: command exited abnormally with status %d", status);
64 endif
65
66 else
67 ## Just let the output flow if the pager is off. That way the
68 ## output from things like "ls -R /" will show up immediately and
69 ## we won't have to buffer all the output.
70 system (cmd);
71 endif
72
73 else
74 error ("ls: expecting all arguments to be character strings");
75 endif
76
77 endfunction