[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ls -F indicators
From: |
Paul Eggert |
Subject: |
Re: ls -F indicators |
Date: |
Fri, 29 Apr 2005 14:07:59 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> bash TAB-completion with readline's `set visible-stats on' uses '%'
> for character-special devices and '#' for block-special devices.
Aack. FreeBSD "ls" uses "%" for whiteouts, and nothing for special
files. I'd rather not have gratuitous incompatibility. Perhaps Jim
should think about the best thing to do here. Maybe we could talk
Bash into using something different for char-specials? Or FreeBSD
into something different for whiteouts?
> ls --color and dircolors support the file type door,
> coloring it by default like sockets, but I am not familiar with that file
> type (I doubt cygwin supports it). What systems have doors, and should
> doors also have a classification character?
Solaris supports it. The classification character is ">". This
wasn't always documented or done right, but the patch below should fix
that.
> Also, POSIX only specifies that `ls -p' denote directories with '/'
That's a clear incompatibility with POSIX, as well as with Solaris,
FreeBSD, etc. I don't see any evidence of this being intentional,
so I think we should just fix it.
I installed this:
Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.280
diff -p -u -r1.280 NEWS
--- NEWS 28 Apr 2005 16:39:32 -0000 1.280
+++ NEWS 29 Apr 2005 20:52:36 -0000
@@ -62,6 +62,12 @@ GNU coreutils NEWS
When POSIXLY_CORRECT is set, "fold file -3" is now equivalent to
"fold file ./-3", not the obviously-erroneous "fold file ./-w3".
+ ls changes:
+
+ -p now appends '/' only to directories; it is equivalent to the
+ new option --indicator-style=directory. Use --file-type or
+ --indicator-style=file-type to get -p's old behavior.
+
nohup changes:
nohup now ignores the umask when creating nohup.out.
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.252
diff -p -u -r1.252 coreutils.texi
--- doc/coreutils.texi 26 Apr 2005 16:44:24 -0000 1.252
+++ doc/coreutils.texi 29 Apr 2005 20:52:37 -0000
@@ -5880,13 +5880,22 @@ Piping a colorized listing through a pag
Append a character to each file name indicating the file type. Also,
for regular files that are executable, append @samp{*}. The file type
indicators are @samp{/} for directories, @samp{@@} for symbolic links,
address@hidden|} for FIFOs, @samp{=} for sockets, and nothing for regular files.
address@hidden|} for FIFOs, @samp{=} for sockets, @samp{>} for doors,
+and nothing for regular files.
@c The following sentence is the same as the one for -d.
Do not follow symbolic links listed on the
command line unless the @option{--dereference-command-line} (@option{-H}),
@option{--dereference} (@option{-L}), or
@option{--dereference-command-line-symlink-to-dir} options are specified.
address@hidden --file-type
address@hidden --indicator-style=file-type
address@hidden --file-type
address@hidden --indicator-style
address@hidden file type, marking
+Append a character to each file name indicating the file type. This is
+like @option{-F}, except that executables are not marked.
+
@item address@hidden
@opindex --indicator-style
Append a character indicator with style @var{word} to entry names,
@@ -5894,10 +5903,13 @@ as follows:
@table @samp
@item none
Do not append any character indicator; this is the default.
address@hidden directory
+Append @samp{/} for directories. This is the same as the @option{-p}
+option.
@item file-type
Append @samp{/} for directories, @samp{@@} for symbolic links, @samp{|}
for FIFOs, @samp{=} for sockets, and nothing for regular files. This is
-the same as the @option{-p} or @option{--file-type} option.
+the same as the @option{--file-type} option.
@item classify
Append @samp{*} for executable regular files, otherwise behave as for
@samp{file-type}. This is the same as the @option{-F} or
@@ -5919,13 +5931,11 @@ List files horizontally, with as many as
separated by @samp{, } (a comma and a space).
@item -p
address@hidden --file-type
address@hidden --indicator-style=file-type
address@hidden --file-type
address@hidden --indicator-style=directory
address@hidden -p
@opindex --indicator-style
@cindex file type, marking
-Append a character to each file name indicating the file type. This is
-like @option{-F}, except that executables are not marked.
+Append a @samp{/} to directory names.
@item -x
@itemx --format=across
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.382
diff -p -u -r1.382 ls.c
--- src/ls.c 12 Apr 2005 07:39:38 -0000 1.382
+++ src/ls.c 29 Apr 2005 20:52:37 -0000
@@ -463,16 +463,18 @@ static uintmax_t file_output_block_size
static bool dired;
/* `none' means don't mention the type of files.
+ `directory' means mention directories.
+ `file_type' means mention file types.
`classify' means mention file types and mark executables.
- `file_type' means mention only file types.
Controlled by -F, -p, and --indicator-style. */
enum indicator_style
{
- none, /* --indicator-style=none */
- classify, /* -F, --indicator-style=classify */
- file_type /* -p, --indicator-style=file-type */
+ none, /* --indicator-style=none */
+ directory_only, /* -p, --indicator-style=directory */
+ file_type, /* --indicator-style=file-type */
+ classify /* -F, --indicator-style=classify */
};
static enum indicator_style indicator_style;
@@ -480,12 +482,12 @@ static enum indicator_style indicator_st
/* Names of indicator styles. */
static char const *const indicator_style_args[] =
{
- "none", "classify", "file-type", NULL
+ "none", "directory", "file-type", "classify", NULL
};
-static enum indicator_style const indicator_style_types[]=
+static enum indicator_style const indicator_style_types[] =
{
- none, classify, file_type
+ none, directory_only, file_type, classify
};
/* True means use colors to mark types. Also define the different
@@ -1545,7 +1547,7 @@ decode_switches (int argc, char **argv)
break;
case 'p':
- indicator_style = file_type;
+ indicator_style = directory_only;
break;
case 'q':
@@ -1775,10 +1777,10 @@ decode_switches (int argc, char **argv)
filename_quoting_options = clone_quoting_options (NULL);
if (get_quoting_style (filename_quoting_options) == escape_quoting_style)
set_char_quoting (filename_quoting_options, ' ', 1);
- if (indicator_style != none)
+ if (file_type <= indicator_style)
{
char const *p;
- for (p = "*=@|" + indicator_style - 1; *p; p++)
+ for (p = "*=>@|" + indicator_style - file_type; *p; p++)
set_char_quoting (filename_quoting_options, *p, 1);
}
@@ -2580,7 +2582,7 @@ gobble_file (char const *name, enum file
/* Avoid following symbolic links when possible, ie, when
they won't be traced and when no indicator is needed. */
if (linkpath
- && (indicator_style != none || check_symlink_color)
+ && (file_type <= indicator_style || check_symlink_color)
&& stat (linkpath, &linkstats) == 0)
{
f->linkok = true;
@@ -3631,7 +3633,7 @@ print_type_indicator (mode_t mode)
if (S_ISREG (mode))
{
if (indicator_style == classify && (mode & S_IXUGO))
- c ='*';
+ c = '*';
else
c = 0;
}
@@ -3639,6 +3641,8 @@ print_type_indicator (mode_t mode)
{
if (S_ISDIR (mode))
c = '/';
+ else if (indicator_style == directory_only)
+ c = 0;
else if (S_ISLNK (mode))
c = '@';
else if (S_ISFIFO (mode))
@@ -3750,21 +3754,16 @@ length_of_file_name_and_frills (const st
if (indicator_style != none)
{
- mode_t filetype = f->stat.st_mode;
+ mode_t mode = f->stat.st_mode;
- if (S_ISREG (filetype))
- {
- if (indicator_style == classify
- && (f->stat.st_mode & S_IXUGO))
- len += 1;
- }
- else if (S_ISDIR (filetype)
- || S_ISLNK (filetype)
- || S_ISFIFO (filetype)
- || S_ISSOCK (filetype)
- || S_ISDOOR (filetype)
- )
- len += 1;
+ len += (S_ISREG (mode)
+ ? (indicator_style == classify && (mode & S_IXUGO))
+ : (S_ISDIR (mode)
+ || (indicator_style != directory_only
+ && (S_ISLNK (mode)
+ || S_ISFIFO (mode)
+ || S_ISSOCK (mode)
+ || S_ISDOOR (mode)))));
}
return len;
@@ -4084,7 +4083,8 @@ Mandatory arguments to long options are
"), stdout);
fputs (_("\
-f do not sort, enable -aU, disable -lst\n\
- -F, --classify append indicator (one of */=@|) to entries\n\
+ -F, --classify append indicator (one of */=>@|) to entries\n\
+ --file-type likewise, except do not append `*'\n\
--format=WORD across -x, commas -m, horizontal -x, long -l,\n\
single-column -1, verbose -l, vertical -C\n\
--full-time like -l --time-style=full-iso\n\
@@ -4105,7 +4105,8 @@ Mandatory arguments to long options are
"), stdout);
fputs (_("\
--indicator-style=WORD append indicator with style WORD to entry
names:\n\
- none (default), classify (-F), file-type (-p)\n\
+ none (default), directory (-p),\n\
+ file-type (--file-type), classify (-F)\n\
-i, --inode with -l, print the index number of each file\n\
-I, --ignore=PATTERN do not list implied entries matching shell
PATTERN\n\
-k like --block-size=1K\n\
@@ -4122,7 +4123,8 @@ Mandatory arguments to long options are
-N, --literal print raw entry names (don't treat e.g. control\n\
characters specially)\n\
-o like -l, but do not list group information\n\
- -p, --file-type append indicator (one of /=@|) to entries\n\
+ -p, --indicator-style=directory\n\
+ append / indicator to directories\n\
"), stdout);
fputs (_("\
-q, --hide-control-chars print ? instead of non graphic characters\n\
Index: tests/ls/file-type
===================================================================
RCS file: /fetish/cu/tests/ls/file-type,v
retrieving revision 1.1
diff -p -u -r1.1 file-type
--- tests/ls/file-type 6 Dec 2002 13:47:40 -0000 1.1
+++ tests/ls/file-type 29 Apr 2005 20:52:37 -0000
@@ -1,5 +1,5 @@
#!/bin/sh
-# contrast ls -F and ls --indicator-style=file-type
+# contrast ls -F, ls -p, and ls --indicator-style=file-type
if test "$VERBOSE" = yes; then
set -x
@@ -40,7 +40,7 @@ fi
fail=0
-ls -1F sub > out || fail=1
+ls -F sub > out || fail=1
cat <<EOF > exp
$block${char}dir/
executable*
@@ -52,7 +52,10 @@ slink-reg@
EOF
sed 's/\*//' exp > exp2
-ls -1 --indicator-style=file-type sub > out2 || fail=1
+ls --indicator-style=file-type sub > out2 || fail=1
+
+sed 's/[@|]$//' exp2 > exp3
+ls -p sub > out3 || fail=1
cmp out exp || fail=1
test $fail = 1 && diff out exp 2> /dev/null
@@ -60,15 +63,11 @@ test $fail = 1 && diff out exp 2> /dev/n
cmp out2 exp2 || fail=1
test $fail = 1 && diff out2 exp2 2> /dev/null
-ls --color -1F sub > out3 || fail=1
-cat <<EOF > exp3
-$block${char}dir/
-executable*
-fifo|
-regular
-slink-dangle@
-slink-dir@
-slink-reg@
-EOF
+cmp out3 exp3 || fail=1
+test $fail = 1 && diff out3 exp3 2> /dev/null
+
+ls --color=auto -F sub > out || fail=1
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
(exit $fail); exit $fail
- Re: ls -F indicators,
Paul Eggert <=