diff options
-rw-r--r-- | contrib/tree-1.6.0-matchdirs.patch | 164 | ||||
-rwxr-xr-x | src/password-store.sh | 7 |
2 files changed, 146 insertions, 25 deletions
diff --git a/contrib/tree-1.6.0-matchdirs.patch b/contrib/tree-1.6.0-matchdirs.patch index de2cfa2..92cd561 100644 --- a/contrib/tree-1.6.0-matchdirs.patch +++ b/contrib/tree-1.6.0-matchdirs.patch @@ -1,17 +1,51 @@ -From 57f931a7a8564379e7b2e5c31301dcd6c0e84b50 Mon Sep 17 00:00:00 2001 +From 59d7a2237500c9439b758910e951bcd5dc48c657 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 4 Apr 2013 08:43:05 -0700 -Subject: [PATCH] Add --matchdirs to check patterns against directories +Subject: [PATCH] Add --matchdirs and --caseinsensitive to matching -This causes pattern matching to include the full contents of any -directories that match the pattern, including sub-directories. +The new --matchdirs option causes pattern matching to include +the full contents of any directories that match the pattern, +including sub-directories. + +The --caseinsensitive option simply makes pattern matching case +insensitive. --- - doc/tree.1 | 10 +++++++++- - tree.c | 46 ++++++++++++++++++++++++++++++++++++++++------ - 2 files changed, 49 insertions(+), 7 deletions(-) + CHANGES | 5 ++++ + README | 4 ++++ + doc/tree.1 | 17 +++++++++++++- + tree.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- + 4 files changed, 91 insertions(+), 14 deletions(-) +diff --git a/CHANGES b/CHANGES +index 10f2e20..004b86a 100644 +--- a/CHANGES ++++ b/CHANGES +@@ -1,3 +1,8 @@ ++Version 1.6.1 ++ - Added --matchdirs flag so that patterns match against directory names and ++ then subsequently descend into sub-directories. ++ - Added --caseinsensitive flag so patterns match without regards to case. ++ + Version 1.6.0 + - Re-org of code into multiple files, split HTML and Unix listdir() into + separate functions, various code cleanups and optimizations. +diff --git a/README b/README +index ab58d82..58767e8 100644 +--- a/README ++++ b/README +@@ -141,6 +141,10 @@ Ujjwal Kumar + - Suggested that tree backslash spaces like ls does for script use. Made + output more like ls. + ++Jason A. Donenfeld ++ - Added --matchdirs flag for matching patterns against directories. ++ - Added --caseinsensitive flag for case insensitive pattern matching. ++ + And many others whom I've failed to keep track of. I should have started + this list years ago. + diff --git a/doc/tree.1 b/doc/tree.1 -index 4b80852..7765f34 100644 +index 4b80852..41d0815 100644 --- a/doc/tree.1 +++ b/doc/tree.1 @@ -21,7 +21,7 @@ @@ -19,39 +53,66 @@ index 4b80852..7765f34 100644 tree \- list contents of directories in a tree-like format. .SH SYNOPSIS -\fBtree\fP [\fB-acdfghilnpqrstuvxACDFQNSUX\fP] [\fB-L\fP \fIlevel\fP [\fB-R\fP]] [\fB-H\fP \fIbaseHREF\fP] [\fB-T\fP \fItitle\fP] [\fB-o\fP \fIfilename\fP] [\fB--nolinks\fP] [\fB-P\fP \fIpattern\fP] [\fB-I\fP \fIpattern\fP] [\fB--inodes\fP] [\fB--device\fP] [\fB--noreport\fP] [\fB--dirsfirst\fP] [\fB--version\fP] [\fB--help\fP] [\fB--filelimit\fP \fI#\fP] [\fB--si\fP] [\fB--prune\fP] [\fB--du\fP] [\fB--timefmt\fP \fIformat\fP] [\fIdirectory\fP ...] -+\fBtree\fP [\fB-acdfghilnpqrstuvxACDFQNSUX\fP] [\fB-L\fP \fIlevel\fP [\fB-R\fP]] [\fB-H\fP \fIbaseHREF\fP] [\fB-T\fP \fItitle\fP] [\fB-o\fP \fIfilename\fP] [\fB--nolinks\fP] [\fB-P\fP \fIpattern\fP] [\fB-I\fP \fIpattern\fP] [\fB--inodes\fP] [\fB--device\fP] [\fB--noreport\fP] [\fB--dirsfirst\fP] [\fB--version\fP] [\fB--help\fP] [\fB--filelimit\fP \fI#\fP] [\fB--si\fP] [\fB--prune\fP] [\fB--du\fP] [\fB--timefmt\fP \fIformat\fP] [\fB--matchdirs\fP] [\fIdirectory\fP ...] ++\fBtree\fP [\fB-acdfghilnpqrstuvxACDFQNSUX\fP] [\fB-L\fP \fIlevel\fP [\fB-R\fP]] [\fB-H\fP \fIbaseHREF\fP] [\fB-T\fP \fItitle\fP] [\fB-o\fP \fIfilename\fP] [\fB--nolinks\fP] [\fB-P\fP \fIpattern\fP] [\fB-I\fP \fIpattern\fP] [\fB--inodes\fP] [\fB--device\fP] [\fB--noreport\fP] [\fB--dirsfirst\fP] [\fB--version\fP] [\fB--help\fP] [\fB--filelimit\fP \fI#\fP] [\fB--si\fP] [\fB--prune\fP] [\fB--du\fP] [\fB--timefmt\fP \fIformat\fP] [\fB--caseinsensitive\fP] [\fB--matchdirs\fP] [\fIdirectory\fP ...] .br .SH DESCRIPTION \fITree\fP is a recursive directory listing program that produces a depth -@@ -123,6 +123,14 @@ Prints (implies -D) and formats the date according to the format string +@@ -123,6 +123,19 @@ Prints (implies -D) and formats the date according to the format string which uses the \fBstrftime\fP(3) syntax. .PP .TP ++.B --caseinsensitive ++If a match pattern is specified by the -P option, this will cause the pattern ++to match without regards to the case of each letter. ++.PP ++.TP +.B --matchdirs +If a match pattern is specified by the -P option, this will cause the pattern +to be applied to directory names (in addition to filenames). In the event of a +match on the directory name, matching is disabled for the directory's -+contents.If the --prune option is used, empty folders that match the pattern ++contents. If the --prune option is used, empty folders that match the pattern +will not be pruned. +.PP +.TP .B -o \fIfilename\fP Send output to \fIfilename\fP. .PP +@@ -314,6 +327,8 @@ Steve Baker (ice@mama.indstate.edu) + HTML output hacked by Francesc Rocher (rocher@econ.udg.es) + .br + Charsets and OS/2 support by Kyosuke Tokoro (NBG01720@nifty.ne.jp) ++.br ++Directory and case matching by Jason A. Donenfeld (Jason@zx2c4.com) + + .SH BUGS AND NOTES + Tree does not prune "empty" directories when the -P and -I options are used by diff --git a/tree.c b/tree.c -index 19cf368..187613d 100644 +index 19cf368..388aae5 100644 --- a/tree.c +++ b/tree.c -@@ -28,7 +28,7 @@ static char *hversion="\t\t tree v1.6.0 %s 1996 - 2011 by Steve Baker and Thomas +@@ -19,16 +19,17 @@ + + #include "tree.h" + +-static char *version ="$Version: $ tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro $"; +-static char *hversion="\t\t tree v1.6.0 %s 1996 - 2011 by Steve Baker and Thomas Moore <br>\n" ++static char *version ="$Version: $ tree v1.6.0 (c) 1996 - 2014 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro, Jason A. Donenfeld $"; ++static char *hversion="\t\t tree v1.6.0 %s 1996 - 2014 by Steve Baker and Thomas Moore <br>\n" + "\t\t HTML output hacked and copyleft %s 1998 by Francesc Rocher <br>\n" +- "\t\t Charsets / OS/2 support %s 2001 by Kyosuke Tokoro\n"; ++ "\t\t Charsets / OS/2 support %s 2001 by Kyosuke Tokoro <br>\n" ++ "\t\t Directory and case matching %s 2014 by Jason A. Donenfeld\n"; + + /* Globals */ bool dflag, lflag, pflag, sflag, Fflag, aflag, fflag, uflag, gflag; bool qflag, Nflag, Qflag, Dflag, inodeflag, devflag, hflag, Rflag; bool Hflag, siflag, cflag, Xflag, duflag, pruneflag; -bool noindent, force_color, nocolor, xdev, noreport, nolinks, flimit, dirsfirst, nosort; -+bool noindent, force_color, nocolor, xdev, noreport, nolinks, flimit, dirsfirst, nosort, matchdirs; ++bool noindent, force_color, nocolor, xdev, noreport, nolinks, flimit, dirsfirst, nosort, matchdirs, caseinsensitive; char *pattern = NULL, *ipattern = NULL, *host = NULL, *title = "Directory Tree", *sp = " "; char *timefmt = NULL; const char *charset = NULL; -@@ -75,12 +75,13 @@ int main(int argc, char **argv) +@@ -75,12 +76,13 @@ int main(int argc, char **argv) char sizebuf[64]; off_t size = 0; mode_t mt; @@ -62,11 +123,11 @@ index 19cf368..187613d 100644 Dflag = qflag = Nflag = Qflag = Rflag = hflag = Hflag = siflag = cflag = FALSE; noindent = force_color = nocolor = xdev = noreport = nolinks = FALSE; - dirsfirst = nosort = inodeflag = devflag = Xflag = FALSE; -+ matchdirs = dirsfirst = nosort = inodeflag = devflag = Xflag = FALSE; ++ caseinsensitive = matchdirs = dirsfirst = nosort = inodeflag = devflag = Xflag = FALSE; duflag = pruneflag = FALSE; flimit = 0; dirs = xmalloc(sizeof(int) * (maxdirs=4096)); -@@ -350,6 +351,11 @@ int main(int argc, char **argv) +@@ -350,6 +352,16 @@ int main(int argc, char **argv) Dflag = TRUE; break; } @@ -75,10 +136,15 @@ index 19cf368..187613d 100644 + matchdirs = TRUE; + break; + } ++ if (!strncmp("--caseinsensitive",argv[i],17)) { ++ j = strlen(argv[i])-1; ++ caseinsensitive = TRUE; ++ break; ++ } } default: fprintf(stderr,"tree: Invalid argument -`%c'.\n",argv[i][j]); -@@ -387,16 +393,17 @@ int main(int argc, char **argv) +@@ -387,16 +399,17 @@ int main(int argc, char **argv) parse_dir_colors(); initlinedraw(0); @@ -99,15 +165,26 @@ index 19cf368..187613d 100644 } if (dflag) pruneflag = FALSE; /* You'll just get nothing otherwise. */ -@@ -534,6 +541,7 @@ void usage(int n) +@@ -517,7 +530,8 @@ void usage(int n) + "usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]]\n" + "\t[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]\n" + "\t[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]\n" +- "\t[--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>]\n"); ++ "\t[--filelimit[=]#] [--si] [--timefmt[=]<f>] [--matchdirs]\n" ++ "\t[--caseinsensitive] [<directory list>]\n"); + if (n < 2) exit(0); + fprintf(stderr, + " ------- Listing options -------\n" +@@ -534,6 +548,8 @@ void usage(int n) " --charset X Use charset X for terminal/HTML and indentation line output.\n" " --filelimit # Do not descend dirs with more than # files in them.\n" " --timefmt <f> Print and format time according to the format <f>.\n" + " --matchdirs Include directory names in -P pattern matching.\n" ++ " --caseinsensitive Match files without regards to case in -P pattern matching.\n" " -o filename Output to file instead of stdout.\n" " -------- File options ---------\n" " -q Print non-printable characters as '?'.\n" -@@ -689,6 +697,8 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e +@@ -689,6 +705,8 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e struct _info **dir, **sav, **p, *sp; struct stat sb; int n; @@ -116,7 +193,7 @@ index 19cf368..187613d 100644 *err = NULL; if (Level >= 0 && lev > Level) return NULL; -@@ -696,7 +706,29 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e +@@ -696,7 +714,29 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e stat(d,&sb); dev = sb.st_dev; } @@ -146,7 +223,7 @@ index 19cf368..187613d 100644 if (dir == NULL) { *err = scopy("error opening dir"); return NULL; -@@ -745,7 +777,9 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e +@@ -745,7 +785,9 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e saveino((*dir)->inode, (*dir)->dev); (*dir)->child = getfulltree(path,lev+1,dev,&((*dir)->size),&((*dir)->err)); } @@ -157,6 +234,49 @@ index 19cf368..187613d 100644 sp = *dir; for(p=dir;*p;p++) *p = *(p+1); n--; +@@ -869,8 +911,19 @@ char *gnu_getcwd() + } + + /* ++ * Returns a lower case version of the argument if case insensitive ++ * mode is enabled. Note that this is static and inline so that we ++ * do not incur penalty when this is running in a tight loop. ++ */ ++static inline char cond_lower(char c) ++{ ++ return caseinsensitive ? tolower(c) : c; ++} ++ ++/* + * Patmatch() code courtesy of Thomas Moore (dark@mama.indstate.edu) + * '|' support added by David MacMahon (davidm@astron.Berkeley.EDU) ++ * Case insensitive support added by Jason A. Donenfeld (Jason@zx2c4.com) + * returns: + * 1 on a match + * 0 on a mismatch +@@ -918,11 +971,11 @@ int patmatch(char *buf, char *pat) + pat += 2; + if(*pat == '\\' && *pat) + pat++; +- if(*buf >= m && *buf <= *pat) ++ if(cond_lower(*buf) >= cond_lower(m) && cond_lower(*buf) <= cond_lower(*pat)) + match = n; + if(!*pat) + pat--; +- } else if(*buf == *pat) match = n; ++ } else if(cond_lower(*buf) == cond_lower(*pat)) match = n; + pat++; + } + buf++; +@@ -940,7 +993,7 @@ int patmatch(char *buf, char *pat) + if(*pat) + pat++; + default: +- match = (*buf++ == *pat); ++ match = (cond_lower(*buf++) == cond_lower(*pat)); + break; + } + pat++; -- 1.9.2 diff --git a/src/password-store.sh b/src/password-store.sh index 706eada..d9d458a 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -275,11 +275,12 @@ case "$command" in echo "Usage: $program $command pass-names..." exit 1 fi - if ! tree --help |& grep -q "^ --matchdirs"; then + if ! tree --version | grep -q "Jason A. Donenfeld"; then echo "ERROR: $program: incompatible tree command" echo echo "Your version of the tree command is missing the relevent patch to add the" - echo "--matchdirs switch. Please ask your distribution to patch your version of" + echo "--matchdirs and --caseinsensitive switches. Please ask your distribution" + echo "to patch your version of" echo "tree with:" echo " http://git.zx2c4.com/password-store/plain/contrib/tree-1.6.0-matchdirs.patch" echo "Sorry for the inconvenience." @@ -287,7 +288,7 @@ case "$command" in fi terms="$@" echo "Search Terms: $terms" - tree -l --noreport -P "*${terms// /*|*}*" --prune --matchdirs "$PREFIX" | tail -n +2 | sed 's/\.gpg$//' + tree -l --noreport -P "*${terms// /*|*}*" --prune --matchdirs --caseinsensitive "$PREFIX" | tail -n +2 | sed 's/\.gpg$//' ;; insert) multiline=0 |