[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
null separated ls output option
From: |
rain1 |
Subject: |
null separated ls output option |
Date: |
Wed, 31 May 2017 22:24:27 +0000 |
User-agent: |
Roundcube Webmail/1.0.6 |
Hello
Please consider accepting this patch I wrote which adds a new -0 feature
to ls.
This emits the entries separated by null bytes (similar to
/proc/$PID/cmdline) which creates a completely unambiguous and simple
output format that doesn't involve any quotation or escaping (like ls -1
and ls -Q1) by using a separator which cannot occur inside a filename
(\0). Inside emacs eshell for example, the output is nicely human
readable with the null separator displayed as ^@.
diff -Naur '--exclude=*~' coreutils-8.27/src/ls.c
coreutils-8.27-ls-0-patch/src/ls.c
--- coreutils-8.27/src/ls.c 2017-01-21 14:53:43.000000000 +0000
+++ coreutils-8.27-ls-0-patch/src/ls.c 2017-05-31 22:05:43.782177300
+0000
@@ -410,6 +410,7 @@
{
long_format, /* -l and other options that imply -l */
one_per_line, /* -1 */
+ null_separated, /* -0 */
many_per_line, /* -C */
horizontal, /* -x */
with_commas /* -m */
@@ -875,12 +876,12 @@
static char const *const format_args[] =
{
"verbose", "long", "commas", "horizontal", "across",
- "vertical", "single-column", NULL
+ "vertical", "single-column", "null-separated", NULL
};
static enum format const format_types[] =
{
long_format, long_format, with_commas, horizontal, horizontal,
- many_per_line, one_per_line
+ many_per_line, one_per_line, null_separated
};
ARGMATCH_VERIFY (format_args, format_types);
@@ -1753,7 +1754,7 @@
{
int oi = -1;
int c = getopt_long (argc, argv,
-
"abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
+
"abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ10",
long_options, &oi);
if (c == -1)
break;
@@ -1949,6 +1950,10 @@
format = one_per_line;
break;
+ case '0':
+ format = null_separated;
+ break;
+
case AUTHOR_OPTION:
print_author = true;
break;
@@ -2763,7 +2768,8 @@
ls uses constant memory while processing the entries
of
this directory. Useful when there are many (millions)
of entries in a directory. */
- if (format == one_per_line && sort_type == sort_none
+ if ((format == one_per_line || format == null_separated)
+ && sort_type == sort_none
&& !print_block_size && !recursive)
{
/* We must call sort_files in spite of
@@ -3770,6 +3776,14 @@
}
break;
+ case null_separated:
+ for (i = 0; i < cwd_n_used; i++)
+ {
+ print_file_name_and_frills (sorted_file[i], 0);
+ putchar ('\0');
+ }
+ break;
+
case many_per_line:
if (! line_length)
print_with_separator (' ');
@@ -5150,7 +5164,8 @@
-x list entries by lines instead of by
columns\n\
-X sort alphabetically by entry extension\n\
-Z, --context print any security context of each file\n\
- -1 list one file per line. Avoid '\\n' with
-q or -b\
+ -1 list one file per line. Avoid '\\n' with
-q or -b\n\
+ -0 separate entries by a null byte.\n\
\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
- null separated ls output option,
rain1 <=