[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Adding --hide option to ls
From: |
Bardur Arantsson |
Subject: |
[PATCH] Adding --hide option to ls |
Date: |
Sun, 26 Sep 2004 11:42:22 +0200 |
User-agent: |
Mutt/1.5.6i |
Hi all,
Being annoyed with seeing the ',,' files/directories
created by GNU arch (well, tla to be precise) I added a
--hide option to ls. It is a weaker form of --ignore and
behaves exactly like --ignore except that it applies
*only* in cases where the user has *not* specified -a or
-A.
In effect:
ls --hide ",,*" => shows no ',,' files.
ls --hide ",,*" -a => shows ',,' files.
ls --hide ",,*" -A => shows ',,' files.
The idea is that the user can specify the --hide option in
a shell alias for ls and effectively hide ',,' (or any
other 'junk' files) files by default, but still be able to
see them by specifying -a or -A (unlike what the --ignore
option does).
The patch applies cleanly against GNU coreutils 5.2.1 (and
is hereby put into the public domain -- do what you will
with it).
Cheers,
Bardur Arantsson
Patch follows:
diff -ur coreutils-5.2.1/src/ls.c coreutils-5.2.1.patched/src/ls.c
--- coreutils-5.2.1/src/ls.c 2004-02-20 21:54:02.000000000 +0100
+++ coreutils-5.2.1.patched/src/ls.c 2004-09-26 09:49:34.515931328 +0200
@@ -231,6 +231,7 @@
static void put_indicator (const struct bin_str *ind);
static int put_indicator_direct (const struct bin_str *ind);
static void add_ignore_pattern (const char *pattern);
+static void add_hide_pattern (const char *pattern);
static void attach (char *dest, const char *dirname, const char *name);
static void clear_files (void);
static void extract_dirs_from_files (const char *dirname,
@@ -589,6 +590,13 @@
static struct ignore_pattern *ignore_patterns;
+/* A linked list of shell-style globbing patterns. If a non-argument
+ file name matches any of these patterns, it is omitted, *unless*
+ -a or -A is specified, in which case it is shown.
+ Controlled by --hide. Multiple --hide options accumulate. */
+
+static struct ignore_pattern *hide_patterns;
+
/* Nonzero means output nongraphic chars in file names as `?'.
(-q, --hide-control-chars)
qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are
@@ -676,7 +684,8 @@
SI_OPTION,
SORT_OPTION,
TIME_OPTION,
- TIME_STYLE_OPTION
+ TIME_STYLE_OPTION,
+ HIDE_OPTION,
};
static struct option const long_options[] =
@@ -704,6 +713,7 @@
{"dereference-command-line-symlink-to-dir", no_argument, 0,
DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION},
{"ignore", required_argument, 0, 'I'},
+ {"hide", required_argument, 0, HIDE_OPTION},
{"indicator-style", required_argument, 0, INDICATOR_STYLE_OPTION},
{"dereference", no_argument, 0, 'L'},
{"literal", no_argument, 0, 'N'},
@@ -1269,6 +1279,7 @@
all_files = 0;
really_all_files = 0;
ignore_patterns = 0;
+ hide_patterns = 0;
/* FIXME: put this in a function. */
{
@@ -1504,6 +1515,10 @@
add_ignore_pattern (optarg);
break;
+ case HIDE_OPTION:
+ add_hide_pattern (optarg);
+ break;
+
case 'L':
dereference = DEREF_ALWAYS;
break;
@@ -2249,17 +2264,37 @@
ignore_patterns = ignore;
}
+/* Add 'pattern' to the list of patterns for which files that match are
+ not listed (unless -a or -A is also specified). */
+static void
+add_hide_pattern (const char *pattern)
+{
+ register struct ignore_pattern *hide;
+
+ hide = xmalloc (sizeof *hide);
+ hide->pattern = pattern;
+ /* Add it to the head of the linked list. */
+ hide->next = hide_patterns;
+ hide_patterns = hide;
+}
+
/* Return nonzero if the file in `next' should be listed. */
static int
file_interesting (const struct dirent *next)
{
- register struct ignore_pattern *ignore;
+ register struct ignore_pattern *ignore, *hide;
for (ignore = ignore_patterns; ignore; ignore = ignore->next)
if (fnmatch (ignore->pattern, next->d_name, FNM_PERIOD) == 0)
return 0;
+ if (!all_files) {
+ for (hide = hide_patterns; hide; hide = hide_patterns->next)
+ if (fnmatch (hide->pattern, next->d_name, FNM_PERIOD) == 0)
+ return 0;
+ }
+
if (really_all_files
|| next->d_name[0] != '.'
|| (all_files
@@ -3956,6 +3991,8 @@
none (default), classify (-F), file-type (-p)\n\
-i, --inode print index number of each file\n\
-I, --ignore=PATTERN do not list implied entries matching shell
PATTERN\n\
+ --hide=PATTERN do not list implied entries matching shell
PATTERN\n\
+ unless either -a or -A are specified\n\
-k like --block-size=1K\n\
"), stdout);
fputs (_("\
--
Bardur Arantsson
<address@hidden>
<address@hidden>
- I wish God were alive to see this...
Homer Simpson | The Simpsons
- [PATCH] Adding --hide option to ls,
Bardur Arantsson <=